Skip to main content

ConfiguredModule

Struct ConfiguredModule 

Source
pub struct ConfiguredModule<M, O> { /* private fields */ }
Expand description

The configured form of module M: what M::for_root(options) and M::from_config() return, so a module does not repeat the wrapper that carries its id, says it is configured and hands its options to register.

register is the module’s own function. It gets Some(options) from for_root, and None from from_config, which means “read the section of the app’s configuration” (a plain M registers with None too).

use navree_kernel::{ConfiguredModule, Module, ModuleBuilder, Navree};

#[derive(Clone)]
struct GreetingOptions(&'static str);

struct GreetingModule;

impl GreetingModule {
    pub fn for_root(options: GreetingOptions) -> impl Module {
        ConfiguredModule::<GreetingModule, _>::for_root(options, register)
    }
}

impl Module for GreetingModule {
    fn register(&self, m: &mut ModuleBuilder) {
        register(m, None);
    }
}

fn register(m: &mut ModuleBuilder, options: Option<GreetingOptions>) {
    let greeting = options.map_or("hello", |options| options.0);
    m.value(greeting.to_owned()).exports::<String>();
}

// The configured instance has the plain module's id.
let configured = GreetingModule::for_root(GreetingOptions("namaste"));
assert_eq!(configured.id(), GreetingModule.id());
assert!(configured.is_configured());
let report = Navree::app().module(configured).validate().expect("valid");
// The app's root module and GreetingModule.
assert_eq!(report.modules.len(), 2);

Implementations§

Source§

impl<M, O> ConfiguredModule<M, O>

Source

pub fn for_root(options: O, register: fn(&mut ModuleBuilder, Option<O>)) -> Self

M configured with options (configure a module once, in the app root).

Source

pub fn from_config(register: fn(&mut ModuleBuilder, Option<O>)) -> Self

M configured from the app’s configuration: register gets None.

Trait Implementations§

Source§

impl<M: 'static, O: Clone + Send + Sync + 'static> Module for ConfiguredModule<M, O>

Source§

fn id(&self) -> ModuleId

The module identity. for_root wrappers override this to return the id of the module type they configure.
Source§

fn is_configured(&self) -> bool

for_root(...) values return true; at most one configured instance per id.
Source§

fn register(&self, m: &mut ModuleBuilder)

Registers everything the module contributes.
Source§

fn name(&self) -> &'static str

The readable module name used in errors and reports.

Auto Trait Implementations§

§

impl<M, O> Forget for ConfiguredModule<M, O>

§

impl<M, O> Freeze for ConfiguredModule<M, O>
where Option<O>: Freeze, fn(&mut ModuleBuilder, Option<O>): Freeze, PhantomData<fn() -> M>: Freeze,

§

impl<M, O> RefUnwindSafe for ConfiguredModule<M, O>

§

impl<M, O> Send for ConfiguredModule<M, O>
where Option<O>: Send, fn(&mut ModuleBuilder, Option<O>): Send, PhantomData<fn() -> M>: Send,

§

impl<M, O> Sync for ConfiguredModule<M, O>
where Option<O>: Sync, fn(&mut ModuleBuilder, Option<O>): Sync, PhantomData<fn() -> M>: Sync,

§

impl<M, O> Unpin for ConfiguredModule<M, O>
where Option<O>: Unpin, fn(&mut ModuleBuilder, Option<O>): Unpin, PhantomData<fn() -> M>: Unpin,

§

impl<M, O> UnsafeUnpin for ConfiguredModule<M, O>

§

impl<M, O> UnwindSafe for ConfiguredModule<M, O>

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self> ⓘ

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self> ⓘ

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<M> IntoModules for M
where M: Module,

Source§

fn into_modules(self) -> Vec<Box<dyn Module>>

Converts into boxed modules, in order.
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> ⓘ
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self> ⓘ

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more