Trait components_arena::ComponentClass [−][src]
pub trait ComponentClass { fn lock() -> &'static ComponentClassLock
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 ComponentClassLock
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
ComponentClassLock
instance from the lock
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 lock() -> &'static ComponentClassLock { static LOCK: ComponentClassLock = ComponentClassLock::new(); &LOCK } }
Required methods
fn lock() -> &'static ComponentClassLock where
Self: Sized,
fn lock() -> &'static ComponentClassLock where
Self: Sized,
Essential for components arena internal mechanic.