Trait ComponentOption

Source
pub trait ComponentOption<T: Deref<Target: Component + Sized>>: Sized {
    // Required method
    fn get_or_insert_with(
        self,
        commands: EntityCommands<'_>,
        insert: impl FnOnce() -> T::Target,
    ) -> RefOrInsert<'_, T>;

    // Provided methods
    fn get_or_insert(
        self,
        commands: EntityCommands<'_>,
        insert: T::Target,
    ) -> RefOrInsert<'_, T> { ... }
    fn get_or_default(self, commands: EntityCommands<'_>) -> RefOrInsert<'_, T>
       where T::Target: Default { ... }
}
Expand description

Extension traits for Option<&T>, Option<&mut T>, and Option<Ref<T>>.

Required Methods§

Source

fn get_or_insert_with( self, commands: EntityCommands<'_>, insert: impl FnOnce() -> T::Target, ) -> RefOrInsert<'_, T>

Unwraps the option or inserts a new one provided by a closure to the entity.

Provided Methods§

Source

fn get_or_insert( self, commands: EntityCommands<'_>, insert: T::Target, ) -> RefOrInsert<'_, T>

Unwraps the option or inserts a new one by-value to the entity.

Source

fn get_or_default(self, commands: EntityCommands<'_>) -> RefOrInsert<'_, T>
where T::Target: Default,

Unwraps the option or inserts a default instance to the entity.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementations on Foreign Types§

Source§

impl<T: Deref<Target: Component + Sized>> ComponentOption<T> for Option<T>

Source§

fn get_or_insert_with( self, commands: EntityCommands<'_>, insert: impl FnOnce() -> <T as Deref>::Target, ) -> RefOrInsert<'_, T>

Implementors§