Trait components_arena::ComponentClass
source · [−]pub trait ComponentClass {
fn token() -> &'static ComponentClassToken
where
Self: Sized;
}
Expand description
An utility trait describing a specific component type.
Normally for a non-generic component type
the component type itself implements ComponentClass
.
For generic components it would be difficult to have
an own ComponentClassToken
instance for every specialization because Rust
does not have “generic statics” feature.
So, if some component type X
is generic, normally you should introduce
common non-generic uninhabited type XComponent
and implement
ComponentClass
for this synthetic type.
Correct implementation should return reference to the one and same
ComponentClassToken
instance from the token
function.
Also it should be guaranteed that no other ComponentClass
implementation
returns same ComponentClassLock
instance.
This requirements can be easily satisfied with private static:
struct MyComponent { /* ... */ }
impl ComponentClass for MyComponent {
fn token() -> &'static ComponentClassToken {
static TOKEN: ComponentClassToken = ComponentClassToken::new();
&TOKEN
}
}
Required Methods
fn token() -> &'static ComponentClassToken where
Self: Sized,
fn token() -> &'static ComponentClassToken where
Self: Sized,
Essential for components arena internal mechanic.