[][src]Trait components_arena::ComponentClass

pub unsafe trait ComponentClass {
    type Index: ComponentIndex;
    type Unique: ComponentUnique;
    fn lock() -> &'static ComponentClassLock;
}

An utility trait describing a specific component type.

Normaly 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 synthetic uninhabited type XComponent and implement ComponentClass for this synthetic type.

Safety

Correct safe implementation should return reference to the one and same ComponentClassLock instance from the lock function.

Also it should be garanteed that no other ComponentClass implementation returns same ComponentClassLock instance.

This requirements can be easaly satisfied with private static:

unsafe impl ComponentClass for MyComponent {
    fn lock() -> &'static ComponentClassLock {
        static CLASS_LOCK: ComponentClassLock = ComponentTokenLock::new();
        &CLASS_LOCK
    }
    // ...
}

Associated Types

type Index: ComponentIndex

First part of compound component id, distincting all alive components.

type Unique: ComponentUnique

Second part of compound component id, distincting all components created during application run time.

Loading content...

Required methods

fn lock() -> &'static ComponentClassLock

Essential for components arena internal mechanic.

Loading content...

Implementors

Loading content...