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§
Sourcefn configure_router(
&self,
router: Router,
self_instance_ptr: ComponentInstancePtr<dyn Controller + Send + Sync>,
) -> Result<Router, ErrorPtr>
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
).
Provided Methods§
Sourcefn path(&self) -> Option<String>
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
.
Sourcefn server_names(&self) -> Option<ServerNameSet>
fn server_names(&self) -> Option<ServerNameSet>
Optional list of server names for which a given controller should be registered.