Trait shaku::Module[][src]

pub trait Module: ModuleInterface {
    type Submodules;
    fn build(context: ModuleBuildContext<Self>) -> Self
    where
        Self: Sized
; }

A module represents a group of services. By implementing traits such as HasComponent on a module, service dependencies are checked at compile time. At runtime, modules hold the components they are associated with.

Modules can also use other modules as submodules, importing specific services for the root module's use. For more details, see the module macro.

Modules are usually created via the module macro.

Example

use shaku::{module, Component, Interface};

trait MyComponent: Interface {}

#[derive(Component)]
#[shaku(interface = MyComponent)]
struct MyComponentImpl;
impl MyComponent for MyComponentImpl {}

// MyModule implements Module and HasComponent<dyn MyComponent>
module! {
    MyModule {
        components = [MyComponentImpl],
        providers = []
    }
}

Associated Types

type Submodules[src]

A container for this module's submodules.

Loading content...

Required methods

fn build(context: ModuleBuildContext<Self>) -> Self where
    Self: Sized
[src]

Create the module instance by resolving the components this module provides.

Loading content...

Implementors

Loading content...