Skip to content

Commit

Permalink
Add a attr.rust.no_placeholder attribute to codegen to force a comp…
Browse files Browse the repository at this point in the history
…onent's reflection to not have a placeholder value specified.

This enables the component not to `impl Default`
  • Loading branch information
abey79 committed Sep 18, 2024
1 parent 6121840 commit 9c51d5b
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 2 deletions.
15 changes: 13 additions & 2 deletions crates/build/re_types_builder/src/codegen/rust/reflection.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use quote::{format_ident, quote};

use crate::{
codegen::{autogen_warning, Target},
ObjectKind, Objects, Reporter, ATTR_RERUN_COMPONENT_REQUIRED,
ObjectKind, Objects, Reporter, ATTR_RERUN_COMPONENT_REQUIRED, ATTR_RUST_NO_PLACEHOLDER,
};

use super::util::{append_tokens, doc_as_lines};
Expand Down Expand Up @@ -111,11 +111,22 @@ fn generate_component_reflection(
obj.is_experimental(),
)
.join("\n");

let placeholder = if obj.attrs.has(ATTR_RUST_NO_PLACEHOLDER) {
quote! {
None
}
} else {
quote! {
Some(#type_name::default().to_arrow()?)
}
};

let quoted_reflection = quote! {
ComponentReflection {
docstring_md: #docstring_md,

placeholder: Some(#type_name::default().to_arrow()?),
placeholder: #placeholder,
}
};
quoted_pairs.push(quote! { (#quoted_name, #quoted_reflection) });
Expand Down
1 change: 1 addition & 0 deletions crates/build/re_types_builder/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,7 @@ pub const ATTR_RUST_NEW_PUB_CRATE: &str = "attr.rust.new_pub_crate";
pub const ATTR_RUST_OVERRIDE_CRATE: &str = "attr.rust.override_crate";
pub const ATTR_RUST_REPR: &str = "attr.rust.repr";
pub const ATTR_RUST_TUPLE_STRUCT: &str = "attr.rust.tuple_struct";
pub const ATTR_RUST_NO_PLACEHOLDER: &str = "attr.rust.no_placeholder";
pub const ATTR_CPP_NO_FIELD_CTORS: &str = "attr.cpp.no_field_ctors";
pub const ATTR_CPP_RENAME_FIELD: &str = "attr.cpp.rename_field";

Expand Down
5 changes: 5 additions & 0 deletions crates/store/re_types/definitions/attributes/rust.fbs
Original file line number Diff line number Diff line change
Expand Up @@ -41,3 +41,8 @@ attribute "attr.rust.new_pub_crate";
/// an object of kind `Blueprint` with `attr.rust.override_crate=re_viewport`, the final
/// object will be generated in `re_viewport/src/blueprint`.
attribute "attr.rust.override_crate";

/// No reflection placeholder value will be generated for this component.
///
/// This enables the component to not `impl Default`. The drawback is that this may result in a `
attribute "attr.rust.no_placeholder";

0 comments on commit 9c51d5b

Please sign in to comment.