pub trait Archetype {
type Indicator: 'static + ComponentBatch + Default;
// Required methods
fn name() -> ArchetypeName;
fn display_name() -> &'static str;
fn required_components() -> Cow<'static, [ComponentName]>;
// Provided methods
fn indicator() -> MaybeOwnedComponentBatch<'static> { ... }
fn recommended_components() -> Cow<'static, [ComponentName]> { ... }
fn optional_components() -> Cow<'static, [ComponentName]> { ... }
fn all_components() -> Cow<'static, [ComponentName]> { ... }
fn from_arrow(
data: impl IntoIterator<Item = (Field, Box<dyn Array>)>
) -> Result<Self, DeserializationError>
where Self: Sized { ... }
fn from_arrow_components(
data: impl IntoIterator<Item = (ComponentName, Box<dyn Array>)>
) -> Result<Self, DeserializationError>
where Self: Sized { ... }
}
Expand description
An archetype is a high-level construct that represents a set of Component
s that usually
play well with each other (i.e. they compose nicely).
Internally, it is no different than a collection of components, but working at that higher layer of abstraction opens opportunities for nicer APIs & tools that wouldn’t be possible otherwise.
E.g. consider the crate::archetypes::Points3D
archetype, which represents the set of
components to consider when working with a 3D point cloud within Rerun.
Required Associated Types§
sourcetype Indicator: 'static + ComponentBatch + Default
type Indicator: 'static + ComponentBatch + Default
The associated indicator component, whose presence indicates that the high-level archetype-based APIs were used to log the data.
§Internal representation
Indicator components are always unit-length null arrays.
Their names follow the pattern rerun.components.{ArchetypeName}Indicator
, e.g.
rerun.components.Points3DIndicator
.
Since null arrays aren’t actually arrays and we don’t actually have any data to shuffle
around per-se, we can’t implement the usual Loggable
traits.
For this reason, indicator components directly implement LoggableBatch
instead, and
bypass the entire iterator machinery.
Required Methods§
sourcefn name() -> ArchetypeName
fn name() -> ArchetypeName
The fully-qualified name of this archetype, e.g. rerun.archetypes.Points2D
.
sourcefn display_name() -> &'static str
fn display_name() -> &'static str
Readable name for displaying in ui.
sourcefn required_components() -> Cow<'static, [ComponentName]>
fn required_components() -> Cow<'static, [ComponentName]>
Returns the names of all components that must be provided by the user when constructing this archetype.
Provided Methods§
sourcefn indicator() -> MaybeOwnedComponentBatch<'static>
fn indicator() -> MaybeOwnedComponentBatch<'static>
Creates a ComponentBatch
out of the associated Self::Indicator
component.
This allows for associating arbitrary indicator components with arbitrary data.
Check out the manual_indicator
API example to see what’s possible.
sourcefn recommended_components() -> Cow<'static, [ComponentName]>
fn recommended_components() -> Cow<'static, [ComponentName]>
Returns the names of all components that should be provided by the user when constructing this archetype.
sourcefn optional_components() -> Cow<'static, [ComponentName]>
fn optional_components() -> Cow<'static, [ComponentName]>
Returns the names of all components that may be provided by the user when constructing this archetype.
sourcefn all_components() -> Cow<'static, [ComponentName]>
fn all_components() -> Cow<'static, [ComponentName]>
Returns the names of all components that must, should and may be provided by the user when constructing this archetype.
The default implementation always does the right thing, at the cost of some runtime allocations. If you know all your components statically, you can override this method to get rid of the extra allocations.
sourcefn from_arrow(
data: impl IntoIterator<Item = (Field, Box<dyn Array>)>
) -> Result<Self, DeserializationError>where
Self: Sized,
fn from_arrow(
data: impl IntoIterator<Item = (Field, Box<dyn Array>)>
) -> Result<Self, DeserializationError>where
Self: Sized,
Given an iterator of Arrow arrays and their respective field metadata, deserializes them into this archetype.
Arrow arrays that are unknown to this Archetype
will simply be ignored and a warning
logged to stderr.
sourcefn from_arrow_components(
data: impl IntoIterator<Item = (ComponentName, Box<dyn Array>)>
) -> Result<Self, DeserializationError>where
Self: Sized,
fn from_arrow_components(
data: impl IntoIterator<Item = (ComponentName, Box<dyn Array>)>
) -> Result<Self, DeserializationError>where
Self: Sized,
Given an iterator of Arrow arrays and their respective ComponentNames
, deserializes them
into this archetype.
Arrow arrays that are unknown to this Archetype
will simply be ignored and a warning
logged to stderr.