Skip to main content

Initializer

Trait Initializer 

Source
pub trait Initializer<S>: Send
where S: Clone + Send + Sync + 'static, AppContext: FromRef<S>,
{ // Required methods fn name(&self) -> String; fn enabled(&self, state: &S) -> bool; fn priority(&self, state: &S) -> i32; // Provided methods fn after_router(&self, router: Router, _state: &S) -> RoadsterResult<Router> { ... } fn before_middleware( &self, router: Router, _state: &S, ) -> RoadsterResult<Router> { ... } fn after_middleware( &self, router: Router, _state: &S, ) -> RoadsterResult<Router> { ... } fn before_serve(&self, router: Router, _state: &S) -> RoadsterResult<Router> { ... } }
Expand description

Provides hooks into various stages of the app’s startup to allow initializing and installing anything that needs to be done during a specific stage of startup of the HTTP service.

Required Methods§

Source

fn name(&self) -> String

Source

fn enabled(&self, state: &S) -> bool

Source

fn priority(&self, state: &S) -> i32

Used to determine the order in which the initializer will run during app initialization. Smaller numbers will run before larger numbers. For example, an initializer with priority -10 will run before an initializer with priority 10.

If two initializers have the same priority, they are not guaranteed to run in any particular order relative to each other. This may be fine for many initializers.

If the order in which your initializer runs doesn’t particularly matter, it’s generally safe to set its priority as 0.

Provided Methods§

Source

fn after_router(&self, router: Router, _state: &S) -> RoadsterResult<Router>

Source

fn before_middleware( &self, router: Router, _state: &S, ) -> RoadsterResult<Router>

Source

fn after_middleware(&self, router: Router, _state: &S) -> RoadsterResult<Router>

Source

fn before_serve(&self, router: Router, _state: &S) -> RoadsterResult<Router>

Dyn Compatibility§

This trait is dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§

Source§

impl<S> Initializer<S> for AnyInitializer<S>
where S: Clone + Send + Sync + 'static, AppContext: FromRef<S>,

Source§

impl<S> Initializer<S> for NormalizePathInitializer
where S: Clone + Send + Sync + 'static, AppContext: FromRef<S>,