Skip to main content

Module

Trait Module 

Source
pub trait Module: Sized {
    type Config;
    type Requirements;
    type Capability;
    type Error: Error + Send + Sync + 'static;
    type Builder: ModuleBuilder<Self>;

    const NAME: &'static str;
}
Expand description

The standard interface that all modules must implement.

A module declares:

  • NAME: A diagnostic name for the module.
  • Config: The configuration type required for initialization.
  • Requirements: The dependencies required for initialization.
  • Capability: The capability facade exposed to consumers.
  • Error: The initialization error type.
  • Builder: The standard builder type that implements ModuleBuilder<Self>.

§Associated Types

  • Config: Use NoConfig if the module requires no configuration.
  • Requirements: Use NoRequirements if the module has no dependencies.
  • Capability: Typically Arc<dyn SomeTrait + Send + Sync>.
  • Error: Must satisfy std::error::Error + Send + Sync + 'static.
  • Builder: Must implement ModuleBuilder<Self>.

§Example

use trait_kit::prelude::*;
use std::sync::Arc;

struct MyModule;
impl Module for MyModule {
    const NAME: &'static str = "my_module";
    type Config = NoConfig;
    type Requirements = NoRequirements;
    type Capability = Arc<i32>;
    type Error = std::convert::Infallible;
    type Builder = MyBuilder;
}

struct MyBuilder;
impl ModuleBuilder<MyModule> for MyBuilder {
    fn build(self) -> Result<Arc<i32>, std::convert::Infallible> {
        Ok(Arc::new(42))
    }
}

Required Associated Constants§

Source

const NAME: &'static str

The diagnostic name of this module.

Required Associated Types§

Source

type Config

The configuration type required for initialization. Use NoConfig if no configuration is needed.

Source

type Requirements

The dependencies required for initialization. Use NoRequirements if no dependencies are needed.

Source

type Capability

The capability facade exposed to consumers. Typically Arc<dyn SomeTrait + Send + Sync>.

Source

type Error: Error + Send + Sync + 'static

The initialization error type. Must satisfy std::error::Error + Send + Sync + 'static.

Source

type Builder: ModuleBuilder<Self>

The standard builder for this module. Must implement ModuleBuilder<Self> (enforced at usage points).

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.

Implementors§