use crate::{ArchetypeName, ComponentName};
pub trait Enum:
Sized + Copy + Clone + std::hash::Hash + PartialEq + Eq + std::fmt::Display + 'static
{
fn variants() -> &'static [Self];
fn docstring_md(self) -> &'static str;
}
#[derive(Clone, Debug, Default)]
pub struct Reflection {
pub components: ComponentReflectionMap,
pub archetypes: ArchetypeReflectionMap,
}
impl Reflection {
pub fn archetype_reflection_from_short_name(
&self,
short_name: &str,
) -> Option<&ArchetypeReflection> {
self.archetypes
.get(&ArchetypeName::from(short_name))
.or_else(|| {
self.archetypes.get(&ArchetypeName::from(format!(
"rerun.archetypes.{short_name}"
)))
})
.or_else(|| {
self.archetypes.get(&ArchetypeName::from(format!(
"rerun.blueprint.archetypes.{short_name}"
)))
})
.or_else(|| {
self.archetypes
.get(&ArchetypeName::from(format!("rerun.{short_name}")))
})
}
}
pub type ComponentReflectionMap = nohash_hasher::IntMap<ComponentName, ComponentReflection>;
#[derive(Clone, Debug)]
pub struct ComponentReflection {
pub docstring_md: &'static str,
pub placeholder: Option<Box<dyn arrow2::array::Array>>,
}
pub type ArchetypeReflectionMap = nohash_hasher::IntMap<ArchetypeName, ArchetypeReflection>;
#[derive(Clone, Debug)]
pub struct ArchetypeReflection {
pub display_name: &'static str,
pub fields: Vec<ArchetypeFieldReflection>,
}
impl ArchetypeReflection {
#[inline]
pub fn required_fields(&self) -> impl Iterator<Item = &ArchetypeFieldReflection> {
self.fields.iter().filter(|field| field.is_required)
}
}
#[derive(Clone, Debug)]
pub struct ArchetypeFieldReflection {
pub component_name: ComponentName,
pub display_name: &'static str,
pub docstring_md: &'static str,
pub is_required: bool,
}