WithConfig

Trait WithConfig 

Source
pub trait WithConfig<C: Default> {
    // Provided method
    fn config() -> C { ... }
}
Expand description

Trait to configure a gate, middleware or related service.

It is useful when you need to pass configuration to a gate, middleware or related service.

§Example


struct AuthGateConfig {
   pub secret: String,
}

impl Default for AuthGateConfig {
  fn default() -> Self {
   Self {
    secret: "my_secret".to_string(),
   }
  }
}

struct AuthGate;

impl WithConfig<AuthGateConfig> for AuthGate {}

impl NgynGate for AuthGate {
  async fn can_activate(cx: &mut NgynContext<'_>) -> bool {
   let config = Self::config();
   config.secret == "my_secret"
  }
}

Provided Methods§

Source

fn config() -> C

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§