Skip to content

Commit

Permalink
Improved reflection (#8432)
Browse files Browse the repository at this point in the history
Misc improvements to the reflection that I had to implement while
investigating forward-compat, migration scripts, etc.
teh-cmc authored Dec 12, 2024
1 parent e1aea95 commit abccbe4
Showing 3 changed files with 755 additions and 661 deletions.
12 changes: 11 additions & 1 deletion crates/build/re_types_builder/src/codegen/rust/reflection.rs
Original file line number Diff line number Diff line change
@@ -178,6 +178,7 @@ fn generate_archetype_reflection(reporter: &Reporter, objects: &Objects) -> Toke
let Some(component_name) = field.typ.fqname() else {
panic!("archetype field must be an object/union or an array/vector of such")
};
let name = &field.name;
let display_name = re_case::to_human_case(&field.name);
let docstring_md = doc_as_lines(
reporter,
@@ -193,8 +194,9 @@ fn generate_archetype_reflection(reporter: &Reporter, objects: &Objects) -> Toke

quote! {
ArchetypeFieldReflection {
component_name: #component_name.into(),
name: #name,
display_name: #display_name,
component_name: #component_name.into(),
docstring_md: #docstring_md,
is_required: #required,
}
@@ -220,6 +222,12 @@ fn generate_archetype_reflection(reporter: &Reporter, objects: &Objects) -> Toke
.join("\n");
}

let scope = if let Some(scope) = obj.scope() {
quote!(Some(#scope))
} else {
quote!(None)
};

let quoted_view_types = obj
.archetype_view_types()
.unwrap_or_default()
@@ -234,6 +242,8 @@ fn generate_archetype_reflection(reporter: &Reporter, objects: &Objects) -> Toke
ArchetypeReflection {
display_name: #display_name,

scope: #scope,

view_types: &[
#(#quoted_view_types,)*
],
1,392 changes: 734 additions & 658 deletions crates/store/re_types/src/reflection/mod.rs

Large diffs are not rendered by default.

12 changes: 10 additions & 2 deletions crates/store/re_types_core/src/reflection.rs
Original file line number Diff line number Diff line change
@@ -238,6 +238,11 @@ pub struct ArchetypeReflection {
/// e.g. `Spatial3DView`.
pub view_types: &'static [&'static str],

/// Does this have a particular scope?
///
/// e.g. `"blueprint"`.
pub scope: Option<&'static str>,

/// All the component fields of the archetype, in the order they appear in the archetype.
pub fields: Vec<ArchetypeFieldReflection>,
}
@@ -253,12 +258,15 @@ impl ArchetypeReflection {
/// Additional information about an archetype's field.
#[derive(Clone, Debug)]
pub struct ArchetypeFieldReflection {
/// The type of the field (it's always a component).
pub component_name: ComponentName,
/// The name of the field (i.e. same as `ComponentDescriptor::archetype_field_name`).
pub name: &'static str,

/// The name of the field in human case.
pub display_name: &'static str,

/// The type of the field (it's always a component).
pub component_name: ComponentName,

/// Markdown docstring for the field (not for the component type).
pub docstring_md: &'static str,

0 comments on commit abccbe4

Please sign in to comment.