diff --git a/crates/re_types_builder/src/codegen/python.rs b/crates/re_types_builder/src/codegen/python.rs index 253b282af53c..74fcf0bb5e1f 100644 --- a/crates/re_types_builder/src/codegen/python.rs +++ b/crates/re_types_builder/src/codegen/python.rs @@ -43,7 +43,7 @@ impl CodeGenerator for PythonCodeGenerator { datatypes_path, arrow_registry, objs, - &objs.ordered_datatypes(), + &objs.ordered_objects(ObjectKind::Datatype.into()), ) .0, ); @@ -57,7 +57,7 @@ impl CodeGenerator for PythonCodeGenerator { components_path, arrow_registry, objs, - &objs.ordered_components(), + &objs.ordered_objects(ObjectKind::Component.into()), ) .0, ); @@ -70,7 +70,7 @@ impl CodeGenerator for PythonCodeGenerator { archetypes_path, arrow_registry, objs, - &objs.ordered_archetypes(), + &objs.ordered_objects(ObjectKind::Archetype.into()), ); filepaths.extend(paths); diff --git a/crates/re_types_builder/src/codegen/rust.rs b/crates/re_types_builder/src/codegen/rust.rs index c08fa1eb216d..2bd45bfd5511 100644 --- a/crates/re_types_builder/src/codegen/rust.rs +++ b/crates/re_types_builder/src/codegen/rust.rs @@ -41,7 +41,7 @@ impl CodeGenerator for RustCodeGenerator { filepaths.extend(create_files( datatypes_path, arrow_registry, - &objects.ordered_datatypes(), + &objects.ordered_objects(ObjectKind::Datatype.into()), )); let components_path = self.crate_path.join("src/components"); @@ -51,7 +51,7 @@ impl CodeGenerator for RustCodeGenerator { filepaths.extend(create_files( components_path, arrow_registry, - &objects.ordered_components(), + &objects.ordered_objects(ObjectKind::Component.into()), )); let archetypes_path = self.crate_path.join("src/archetypes"); @@ -61,7 +61,7 @@ impl CodeGenerator for RustCodeGenerator { filepaths.extend(create_files( archetypes_path, arrow_registry, - &objects.ordered_archetypes(), + &objects.ordered_objects(ObjectKind::Archetype.into()), )); filepaths diff --git a/crates/re_types_builder/src/objects.rs b/crates/re_types_builder/src/objects.rs index 677779a7c7b3..8c5a7adef4b5 100644 --- a/crates/re_types_builder/src/objects.rs +++ b/crates/re_types_builder/src/objects.rs @@ -81,22 +81,18 @@ impl Objects { .unwrap() } - /// Returns all available datatypes, pre-sorted in ascending order based on their `order` + /// Returns all available objects, pre-sorted in ascending order based on their `order` /// attribute. - pub fn ordered_datatypes(&self) -> Vec<&Object> { - self.ordered_objects(ObjectKind::Datatype.into()) - } + pub fn ordered_objects_mut(&mut self, kind: Option) -> Vec<&mut Object> { + let objs = self + .objects + .values_mut() + .filter(|obj| kind.map_or(true, |kind| obj.kind == kind)); - /// Returns all available components, pre-sorted in ascending order based on their `order` - /// attribute. - pub fn ordered_components(&self) -> Vec<&Object> { - self.ordered_objects(ObjectKind::Component.into()) - } + let mut objs = objs.collect::>(); + objs.sort_by_key(|anyobj| anyobj.order()); - /// Returns all available archetypes, pre-sorted in ascending order based on their `order` - /// attribute. - pub fn ordered_archetypes(&self) -> Vec<&Object> { - self.ordered_objects(ObjectKind::Archetype.into()) + objs } /// Returns all available objects, pre-sorted in ascending order based on their `order` @@ -666,6 +662,44 @@ impl Type { _ => unreachable!("{typ:#?}"), } } + + /// True if this is some kind of array/vector. + pub fn is_plural(&self) -> bool { + match self { + Type::Array { + elem_type: _, + length: _, + } + | Type::Vector { elem_type: _ } => true, + Type::UInt8 + | Type::UInt16 + | Type::UInt32 + | Type::UInt64 + | Type::Int8 + | Type::Int16 + | Type::Int32 + | Type::Int64 + | Type::Bool + | Type::Float16 + | Type::Float32 + | Type::Float64 + | Type::String + | Type::Object(_) => false, + } + } + + /// `Some(fqname)` if this is an `Object` or an `Array`/`Vector` of `Object`s. + pub fn fqname(&self) -> Option<&str> { + match self { + Type::Object(fqname) => Some(fqname.as_str()), + Type::Array { + elem_type, + length: _, + } + | Type::Vector { elem_type } => elem_type.fqname(), + _ => None, + } + } } /// The underlying element type for arrays/vectors/maps. @@ -725,6 +759,14 @@ impl ElementType { _ => unreachable!("{inner_type:#?}"), } } + + /// `Some(fqname)` if this is an `Object`. + pub fn fqname(&self) -> Option<&str> { + match self { + ElementType::Object(fqname) => Some(fqname.as_str()), + _ => None, + } + } } // --- Common ---