pub struct Expando { /* private fields */ }Expand description
A lazy collection of values of every type.
An Expando contains a single instance of every type. The values are instantiated lazily when accessed. Useful for letting modules add their own state to context objects without requiring the context object itself to know about the types in every module.
Typically the type a module uses in the Expando will be private to that module, which lets the module know that no other code is accessing its slot on the expando.
Implementations§
Source§impl Expando
impl Expando
Sourcepub fn get<T: Any + Send + Sync + Default + 'static>(&self) -> Arc<T>
pub fn get<T: Any + Send + Sync + Default + 'static>(&self) -> Arc<T>
Get the slot in the expando associated with the given type.
The slot is added to the expando lazily but the same instance is returned every time the expando is queried for the same type.
Sourcepub fn get_or_init<T: Any + Send + Sync + 'static>(
&self,
init: impl FnOnce() -> T,
) -> Arc<T>
pub fn get_or_init<T: Any + Send + Sync + 'static>( &self, init: impl FnOnce() -> T, ) -> Arc<T>
Get the slot in the expando associated with the given type, running init to initialize
the slot if needed.
The slot is added to the expando lazily but the same instance is returned every time the expando is queried for the same type.
Sourcepub fn get_or_try_init<T: Any + Send + Sync + 'static, E>(
&self,
try_init: impl FnOnce() -> Result<T, E>,
) -> Result<Arc<T>, E>
pub fn get_or_try_init<T: Any + Send + Sync + 'static, E>( &self, try_init: impl FnOnce() -> Result<T, E>, ) -> Result<Arc<T>, E>
Get the slot in the expando associated with the given type, running try_init to initialize
the slot if needed. Returns an error only if try_init returns an error.
The slot is added to the expando lazily but the same instance is returned every time the expando is queried for the same type.
Trait Implementations§
Auto Trait Implementations§
impl !Freeze for Expando
impl !RefUnwindSafe for Expando
impl Send for Expando
impl Sync for Expando
impl Unpin for Expando
impl UnsafeUnpin for Expando
impl !UnwindSafe for Expando
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
§impl<T, D> Encode<Ambiguous1, D> for Twhere
D: ResourceDialect,
impl<T, D> Encode<Ambiguous1, D> for Twhere
D: ResourceDialect,
§impl<T, D> Encode<Ambiguous2, D> for Twhere
D: ResourceDialect,
impl<T, D> Encode<Ambiguous2, D> for Twhere
D: ResourceDialect,
§impl<F, N> FidlIntoNative<Box<N>> for Fwhere
F: FidlIntoNative<N>,
impl<F, N> FidlIntoNative<Box<N>> for Fwhere
F: FidlIntoNative<N>,
fn fidl_into_native(self) -> Box<N>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more