Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a attr.rust.no_placeholder attribute to codegen #7440

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
6 changes: 6 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,9 @@ 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
/// `ComponentFallbackError::MissingPlaceholderValue` error when using this component with the fallback system.
attribute "attr.rust.no_placeholder";
Loading