pub trait Controller: AnySync {
    // Required methods
    fn configure_router(
        &self,
        router: Router,
        self_instance_ptr: ComponentInstancePtr<dyn Controller + Send + Sync>
    ) -> Result<Router, ErrorPtr>;
    fn create_router(&self) -> Result<Router, ErrorPtr>;
    fn post_configure_router(&self, router: Router) -> Result<Router, ErrorPtr>;

    // Provided methods
    fn path(&self) -> Option<String> { ... }
    fn server_names(&self) -> Option<ServerNameSet> { ... }
}
Expand description

Main trait for Components used as controllers - collections of web handlers being functions contained in typical structs. Such approach allows for injecting other components via dependency injection, and therefore, creating advanced applications with proper architecture.

Required Methods§

source

fn configure_router( &self, router: Router, self_instance_ptr: ComponentInstancePtr<dyn Controller + Send + Sync> ) -> Result<Router, ErrorPtr>

Configures a Router to handle incoming requests. Passed instance ptr points to the controller component being processed (Self).

source

fn create_router(&self) -> Result<Router, ErrorPtr>

Creates a Router which is then passed to configure_router.

source

fn post_configure_router(&self, router: Router) -> Result<Router, ErrorPtr>

Adds any post-route configuration to the Router.

Provided Methods§

source

fn path(&self) -> Option<String>

Prefix for all paths contained in the controller, e.g. controller path of /abc and handler path of /xyz results in final path of /abc/xyz.

source

fn server_names(&self) -> Option<ServerNameSet>

Optional list of server names for which given controller should be registered.

Implementations§

source§

impl dyn Controller + Send + Sync

source

pub fn is<_T>(&self) -> boolwhere _T: Any, Self: Downcast<_T>,

source

pub fn downcast_ref<_T>(&self) -> Result<&_T, TypeMismatch>where _T: Any, Self: Downcast<_T>,

source

pub fn downcast_mut<_T>(&mut self) -> Result<&mut _T, TypeMismatch>where _T: Any, Self: Downcast<_T>,

source

pub fn downcast<_T>( self: Box<Self> ) -> Result<Box<_T>, DowncastError<Box<Self>>>where _T: Any, Self: Downcast<_T>,

source

pub fn downcast_rc<_T>( self: Rc<Self> ) -> Result<Rc<_T>, DowncastError<Rc<Self>>>where _T: Any, Self: Downcast<_T>,

source

pub fn downcast_arc<_T>( self: Arc<Self> ) -> Result<Arc<_T>, DowncastError<Arc<Self>>>where _T: AnySync, Self: DowncastSync<_T>,

Trait Implementations§

source§

impl<_T> Downcast<_T> for dyn Controller + Send + Syncwhere _T: Any,

source§

impl<_T> DowncastSync<_T> for dyn Controller + Send + Syncwhere _T: AnySync,

source§

fn downcast_arc(self: Arc<Self>) -> Result<Arc<T>, DowncastError<Arc<Self>>>

source§

impl Injectable for dyn Controller + Sync + Send

Implementors§