PluginApp

Trait PluginApp 

Source
pub trait PluginApp: 'static {
    type Config: Config;

    // Required methods
    fn new(config: Option<Self::Config>) -> Self;
    fn config(&self) -> &Self::Config;
    fn into_config(self) -> Self::Config;

    // Provided method
    fn start(&self) { ... }
}
Expand description

§Example

#[derive(Serialize, Deserialize, Debug, Default)]
pub struct Config {
    s: String,
}

pub struct App {
    config: Config,
}

impl PluginApp for App {
    type Config = Config;

    fn new(config: Option<Self::Config>) -> Self {
        Self {
            config: config.unwrap_or_default(),
        }
    }

    fn config(&self) -> &Self::Config {
        &self.config
    }

    fn into_config(self) -> Self::Config {
        self.config
    }
}

Required Associated Types§

Required Methods§

Source

fn new(config: Option<Self::Config>) -> Self

Source

fn config(&self) -> &Self::Config

Source

fn into_config(self) -> Self::Config

Provided Methods§

Source

fn start(&self)

Can be used to start services requiring to access the PluginApp through PluginHandler::with_app() or PluginHandler::app().

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§