Trait NgynGate

Source
pub trait NgynGate {
    // Provided method
    async fn can_activate(cx: &mut NgynContext<'_>) -> bool { ... }
}
Expand description

Trait for implementing a gate.

Gates are how Ngyn determines if a route can activate. Sometimes, a route may need to be guarded by certain conditions. For instance, restricting access to a route based on the user’s role, or checking if the user is authenticated. Typically, gates are used for this purpose.

§Examples


struct AuthGate;

impl NgynGate for AuthGate {
   async fn can_activate(cx: &mut NgynContext<'_>) -> bool {
     // Check if the user is authenticated
     // If the user is authenticated, return true
     // Otherwise, return false
      false
    }
}

Provided Methods§

Source

async fn can_activate(cx: &mut NgynContext<'_>) -> bool

Determines if the gate can activate for the given request.

§Arguments
  • cx - The request context to check.
§Returns

Returns true if the route can activate, false otherwise.

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§