Trait Controller

Source
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

The main trait for Components used as controllers - collections of web handlers being functions contained in typical structs. This 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 a final path of /abc/xyz.

Source

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

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

Implementations§

Source§

impl dyn Controller + Send + Sync

Source

pub fn is<_T>(&self) -> bool
where _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 + Sync
where _T: Any,

Source§

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

Source§

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

Source§

impl Injectable for dyn Controller + Sync + Send

Implementors§