[][src]Trait shaku::HasComponent

pub trait HasComponent<I: Interface + ?Sized>: ModuleInterface {
    fn build_component(context: &mut ModuleBuildContext<Self>) -> Arc<I>
    where
        Self: Module + Sized
;
fn resolve(&self) -> Arc<I>;
fn resolve_ref(&self) -> &I;
fn resolve_mut(&mut self) -> Option<&mut I>; }

Indicates that a module contains a component which implements the interface.

Required methods

fn build_component(context: &mut ModuleBuildContext<Self>) -> Arc<I> where
    Self: Module + Sized

Build the component during module build. Usually this involves calling ModuleBuildContext::build_component with the implementation.

fn resolve(&self) -> Arc<I>

Get a reference to the component. The ownership of the component is shared via Arc.

Example

let foo: Arc<dyn Foo> = module.resolve();

fn resolve_ref(&self) -> &I

Get a reference to the component.

Example

let foo: &dyn Foo = module.resolve_ref();

fn resolve_mut(&mut self) -> Option<&mut I>

Get a mutable reference to the component.

If the component is jointly owned (an Arc<I> reference to the component exists outside of this module), then None will be returned as it is unsafe to take a mutable reference without exclusive ownership of the component.

Example

let foo: &mut dyn Foo = module.resolve_mut().unwrap();
Loading content...

Implementors

Loading content...