Skip to content

Commit

Permalink
{Datatype,Component,Archetype}Name
Browse files Browse the repository at this point in the history
  • Loading branch information
teh-cmc committed Jun 14, 2023
1 parent 303a921 commit 06c5aaf
Show file tree
Hide file tree
Showing 13 changed files with 73 additions and 65 deletions.
2 changes: 1 addition & 1 deletion crates/re_types/source_hash.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# This is a sha256 hash for all direct and indirect dependencies of this crate's build script.
# It can be safely removed at anytime to force the build script to run again.
# Check out build.rs to see how it's computed.
95c13226f31d47e4639e155fc80ee6830579c50e38ee1d997b4bda4d23ba03b6
ff283f9ec04e0f8082680c9d3e5c598464c9f526fc2388ccc5b687f9bbd91713
50 changes: 25 additions & 25 deletions crates/re_types/src/archetypes/points2d.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,48 +41,48 @@ pub struct Points2D {
}

impl Points2D {
pub const REQUIRED_COMPONENTS: [::std::borrow::Cow<'static, str>; 1] =
[::std::borrow::Cow::Borrowed("rerun.components.Point2D")];
pub const REQUIRED_COMPONENTS: [crate::ComponentName; 1] =
[crate::ComponentName::Borrowed("rerun.components.Point2D")];

pub const RECOMMENDED_COMPONENTS: [::std::borrow::Cow<'static, str>; 2] = [
::std::borrow::Cow::Borrowed("rerun.components.Radius"),
::std::borrow::Cow::Borrowed("rerun.components.Color"),
pub const RECOMMENDED_COMPONENTS: [crate::ComponentName; 2] = [
crate::ComponentName::Borrowed("rerun.components.Radius"),
crate::ComponentName::Borrowed("rerun.components.Color"),
];

pub const OPTIONAL_COMPONENTS: [::std::borrow::Cow<'static, str>; 5] = [
::std::borrow::Cow::Borrowed("rerun.components.Label"),
::std::borrow::Cow::Borrowed("rerun.components.DrawOrder"),
::std::borrow::Cow::Borrowed("rerun.components.ClassId"),
::std::borrow::Cow::Borrowed("rerun.components.KeypointId"),
::std::borrow::Cow::Borrowed("rerun.components.InstanceKey"),
pub const OPTIONAL_COMPONENTS: [crate::ComponentName; 5] = [
crate::ComponentName::Borrowed("rerun.components.Label"),
crate::ComponentName::Borrowed("rerun.components.DrawOrder"),
crate::ComponentName::Borrowed("rerun.components.ClassId"),
crate::ComponentName::Borrowed("rerun.components.KeypointId"),
crate::ComponentName::Borrowed("rerun.components.InstanceKey"),
];

pub const ALL_COMPONENTS: [::std::borrow::Cow<'static, str>; 8] = [
::std::borrow::Cow::Borrowed("rerun.components.Point2D"),
::std::borrow::Cow::Borrowed("rerun.components.Radius"),
::std::borrow::Cow::Borrowed("rerun.components.Color"),
::std::borrow::Cow::Borrowed("rerun.components.Label"),
::std::borrow::Cow::Borrowed("rerun.components.DrawOrder"),
::std::borrow::Cow::Borrowed("rerun.components.ClassId"),
::std::borrow::Cow::Borrowed("rerun.components.KeypointId"),
::std::borrow::Cow::Borrowed("rerun.components.InstanceKey"),
pub const ALL_COMPONENTS: [crate::ComponentName; 8] = [
crate::ComponentName::Borrowed("rerun.components.Point2D"),
crate::ComponentName::Borrowed("rerun.components.Radius"),
crate::ComponentName::Borrowed("rerun.components.Color"),
crate::ComponentName::Borrowed("rerun.components.Label"),
crate::ComponentName::Borrowed("rerun.components.DrawOrder"),
crate::ComponentName::Borrowed("rerun.components.ClassId"),
crate::ComponentName::Borrowed("rerun.components.KeypointId"),
crate::ComponentName::Borrowed("rerun.components.InstanceKey"),
];
}

impl crate::Archetype for Points2D {
fn name() -> ::std::borrow::Cow<'static, str> {
::std::borrow::Cow::Borrowed("rerun.archetypes.Points2D")
fn name() -> crate::ArchetypeName {
crate::ArchetypeName::Borrowed("rerun.archetypes.Points2D")
}

fn required_components() -> Vec<::std::borrow::Cow<'static, str>> {
fn required_components() -> Vec<crate::ComponentName> {
Self::REQUIRED_COMPONENTS.to_vec()
}

fn recommended_components() -> Vec<::std::borrow::Cow<'static, str>> {
fn recommended_components() -> Vec<crate::ComponentName> {
Self::RECOMMENDED_COMPONENTS.to_vec()
}

fn optional_components() -> Vec<::std::borrow::Cow<'static, str>> {
fn optional_components() -> Vec<crate::ComponentName> {
Self::OPTIONAL_COMPONENTS.to_vec()
}

Expand Down
4 changes: 2 additions & 2 deletions crates/re_types/src/components/class_id.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
pub struct ClassId(pub u16);

impl crate::Component for ClassId {
fn name() -> ::std::borrow::Cow<'static, str> {
::std::borrow::Cow::Borrowed("rerun.components.ClassId")
fn name() -> crate::ComponentName {
crate::ComponentName::Borrowed("rerun.components.ClassId")
}

#[allow(clippy::wildcard_imports)]
Expand Down
4 changes: 2 additions & 2 deletions crates/re_types/src/components/color.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@
pub struct Color(pub u32);

impl crate::Component for Color {
fn name() -> ::std::borrow::Cow<'static, str> {
::std::borrow::Cow::Borrowed("rerun.components.Color")
fn name() -> crate::ComponentName {
crate::ComponentName::Borrowed("rerun.components.Color")
}

#[allow(clippy::wildcard_imports)]
Expand Down
4 changes: 2 additions & 2 deletions crates/re_types/src/components/draw_order.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@
pub struct DrawOrder(pub f32);

impl crate::Component for DrawOrder {
fn name() -> ::std::borrow::Cow<'static, str> {
::std::borrow::Cow::Borrowed("rerun.components.DrawOrder")
fn name() -> crate::ComponentName {
crate::ComponentName::Borrowed("rerun.components.DrawOrder")
}

#[allow(clippy::wildcard_imports)]
Expand Down
4 changes: 2 additions & 2 deletions crates/re_types/src/components/instance_key.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
pub struct InstanceKey(pub u64);

impl crate::Component for InstanceKey {
fn name() -> ::std::borrow::Cow<'static, str> {
::std::borrow::Cow::Borrowed("rerun.components.InstanceKey")
fn name() -> crate::ComponentName {
crate::ComponentName::Borrowed("rerun.components.InstanceKey")
}

#[allow(clippy::wildcard_imports)]
Expand Down
4 changes: 2 additions & 2 deletions crates/re_types/src/components/keypoint_id.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@
pub struct KeypointId(pub u16);

impl crate::Component for KeypointId {
fn name() -> ::std::borrow::Cow<'static, str> {
::std::borrow::Cow::Borrowed("rerun.components.KeypointId")
fn name() -> crate::ComponentName {
crate::ComponentName::Borrowed("rerun.components.KeypointId")
}

#[allow(clippy::wildcard_imports)]
Expand Down
4 changes: 2 additions & 2 deletions crates/re_types/src/components/label.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
pub struct Label(pub String);

impl crate::Component for Label {
fn name() -> ::std::borrow::Cow<'static, str> {
::std::borrow::Cow::Borrowed("rerun.components.Label")
fn name() -> crate::ComponentName {
crate::ComponentName::Borrowed("rerun.components.Label")
}

#[allow(clippy::wildcard_imports)]
Expand Down
4 changes: 2 additions & 2 deletions crates/re_types/src/components/point2d.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
pub struct Point2D(pub crate::datatypes::Vec2D);

impl crate::Component for Point2D {
fn name() -> ::std::borrow::Cow<'static, str> {
::std::borrow::Cow::Borrowed("rerun.components.Point2D")
fn name() -> crate::ComponentName {
crate::ComponentName::Borrowed("rerun.components.Point2D")
}

#[allow(clippy::wildcard_imports)]
Expand Down
4 changes: 2 additions & 2 deletions crates/re_types/src/components/radius.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
pub struct Radius(pub f32);

impl crate::Component for Radius {
fn name() -> ::std::borrow::Cow<'static, str> {
::std::borrow::Cow::Borrowed("rerun.components.Radius")
fn name() -> crate::ComponentName {
crate::ComponentName::Borrowed("rerun.components.Radius")
}

#[allow(clippy::wildcard_imports)]
Expand Down
4 changes: 2 additions & 2 deletions crates/re_types/src/datatypes/vec2d.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
pub struct Vec2D(pub [f32; 2]);

impl crate::Datatype for Vec2D {
fn name() -> ::std::borrow::Cow<'static, str> {
::std::borrow::Cow::Borrowed("rerun.datatypes.Vec2D")
fn name() -> crate::DatatypeName {
crate::DatatypeName::Borrowed("rerun.datatypes.Vec2D")
}

#[allow(clippy::wildcard_imports)]
Expand Down
22 changes: 15 additions & 7 deletions crates/re_types/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -71,31 +71,39 @@
//! auto-generated class.
//! The simplest way to get started is to look at any of the existing examples.

use std::borrow::Cow;
// ---

pub type DatatypeName = ::std::borrow::Cow<'static, str>;

/// A [`Datatype`] describes plain old data.
pub trait Datatype {
fn name() -> Cow<'static, str>;
fn name() -> DatatypeName;

fn to_arrow_datatype() -> arrow2::datatypes::DataType;
}

pub type ComponentName = ::std::borrow::Cow<'static, str>;

pub trait Component {
fn name() -> Cow<'static, str>;
fn name() -> ComponentName;

fn to_arrow_datatype() -> arrow2::datatypes::DataType;
}

pub type ArchetypeName = ::std::borrow::Cow<'static, str>;

pub trait Archetype {
fn name() -> Cow<'static, str>;
fn name() -> ArchetypeName;

fn required_components() -> Vec<Cow<'static, str>>;
fn recommended_components() -> Vec<Cow<'static, str>>;
fn optional_components() -> Vec<Cow<'static, str>>;
fn required_components() -> Vec<ComponentName>;
fn recommended_components() -> Vec<ComponentName>;
fn optional_components() -> Vec<ComponentName>;

fn to_arrow_datatypes() -> Vec<arrow2::datatypes::DataType>;
}

// ---

/// Number of decimals shown for all vector display methods.
pub const DISPLAY_PRECISION: usize = 3;

Expand Down
28 changes: 14 additions & 14 deletions crates/re_types_builder/src/codegen/rust.rs
Original file line number Diff line number Diff line change
Expand Up @@ -426,8 +426,8 @@ fn quote_trait_impls_from_obj(arrow_registry: &ArrowRegistry, obj: &Object) -> S
format!(
r#"
impl crate::Datatype for {name} {{
fn name() -> ::std::borrow::Cow<'static, str> {{
::std::borrow::Cow::Borrowed({fqname:?})
fn name() -> crate::DatatypeName {{
crate::DatatypeName::Borrowed({fqname:?})
}}
#[allow(clippy::wildcard_imports)]
Expand All @@ -444,8 +444,8 @@ fn quote_trait_impls_from_obj(arrow_registry: &ArrowRegistry, obj: &Object) -> S
format!(
r#"
impl crate::Component for {name} {{
fn name() -> ::std::borrow::Cow<'static, str> {{
::std::borrow::Cow::Borrowed({fqname:?})
fn name() -> crate::ComponentName {{
crate::ComponentName::Borrowed({fqname:?})
}}
#[allow(clippy::wildcard_imports)]
Expand All @@ -464,7 +464,7 @@ fn quote_trait_impls_from_obj(arrow_registry: &ArrowRegistry, obj: &Object) -> S
let num_components = components.len();
let components = components
.into_iter()
.map(|fqname| format!("::std::borrow::Cow::Borrowed({fqname:?})"))
.map(|fqname| format!("crate::ComponentName::Borrowed({fqname:?})"))
.collect::<Vec<_>>()
.join(", ");

Expand All @@ -484,29 +484,29 @@ fn quote_trait_impls_from_obj(arrow_registry: &ArrowRegistry, obj: &Object) -> S
format!(
r#"
impl {name} {{
pub const REQUIRED_COMPONENTS: [::std::borrow::Cow<'static, str>; {num_required}] = [{required}];
pub const REQUIRED_COMPONENTS: [crate::ComponentName; {num_required}] = [{required}];
pub const RECOMMENDED_COMPONENTS: [::std::borrow::Cow<'static, str>; {num_recommended}] = [{recommended}];
pub const RECOMMENDED_COMPONENTS: [crate::ComponentName; {num_recommended}] = [{recommended}];
pub const OPTIONAL_COMPONENTS: [::std::borrow::Cow<'static, str>; {num_optional}] = [{optional}];
pub const OPTIONAL_COMPONENTS: [crate::ComponentName; {num_optional}] = [{optional}];
pub const ALL_COMPONENTS: [::std::borrow::Cow<'static, str>; {num_all}] = [{all}];
pub const ALL_COMPONENTS: [crate::ComponentName; {num_all}] = [{all}];
}}
impl crate::Archetype for {name} {{
fn name() -> ::std::borrow::Cow<'static, str> {{
::std::borrow::Cow::Borrowed({fqname:?})
fn name() -> crate::ArchetypeName {{
crate::ArchetypeName::Borrowed({fqname:?})
}}
fn required_components() -> Vec<::std::borrow::Cow<'static, str>> {{
fn required_components() -> Vec<crate::ComponentName> {{
Self::REQUIRED_COMPONENTS.to_vec()
}}
fn recommended_components() -> Vec<::std::borrow::Cow<'static, str>> {{
fn recommended_components() -> Vec<crate::ComponentName> {{
Self::RECOMMENDED_COMPONENTS.to_vec()
}}
fn optional_components() -> Vec<::std::borrow::Cow<'static, str>> {{
fn optional_components() -> Vec<crate::ComponentName> {{
Self::OPTIONAL_COMPONENTS.to_vec()
}}
Expand Down

0 comments on commit 06c5aaf

Please sign in to comment.