[−][src]Trait gotham::handler::NewHandler
A type which is used to spawn new Handler
values. When implementing a custom Handler
type,
this is used to define how instances of the Handler
are created.
The Instance
associated type is usually Self
in the simple case, but can be a different
type where greater control is needed over lifetimes.
Examples
A custom handler which implements NewHandler
by copying itself.
#[derive(Copy, Clone)] struct MyCustomHandler; impl NewHandler for MyCustomHandler { type Instance = Self; fn new_handler(&self) -> Result<Self::Instance> { Ok(*self) } } impl Handler for MyCustomHandler { fn handle(self, _state: State) -> Pin<Box<HandlerFuture>> { // Implementation elided. } }
A custom handler which implements NewHandler
using a specific Instance
type.
#[derive(Copy, Clone)] struct MyValueInstantiatingHandler; impl NewHandler for MyValueInstantiatingHandler { type Instance = MyHandler; fn new_handler(&self) -> Result<Self::Instance> { Ok(MyHandler) } } struct MyHandler; impl Handler for MyHandler { fn handle(self, _state: State) -> Pin<Box<HandlerFuture>> { // Implementation elided. } }
Associated Types
Loading content...Required methods
fn new_handler(&self) -> Result<Self::Instance>
Create and return a new Handler
value.
Implementors
impl NewHandler for DirHandler
[src]
type Instance = Self
fn new_handler(&self) -> Result<Self::Instance>
[src]
impl NewHandler for FileHandler
[src]
type Instance = Self
fn new_handler(&self) -> Result<Self::Instance>
[src]
impl NewHandler for Router
[src]
impl<F, H> NewHandler for F where
F: Fn() -> Result<H> + Send + Sync + RefUnwindSafe,
H: Handler + Send,
[src]
F: Fn() -> Result<H> + Send + Sync + RefUnwindSafe,
H: Handler + Send,