Struct saphir::controller::BasicController
source · pub struct BasicController<C> { /* private fields */ }
Expand description
An helper struct embedding a ControllerDispatch
.
Implementations
sourceimpl<C: Send + Sync> BasicController<C>
impl<C: Send + Sync> BasicController<C>
sourcepub fn add<F, R: ToRegex>(&self, method: Method, path: R, delegate_func: F)where
for<'r, 's, 't0> F: 'static + Fn(&'r C, &'s SyncRequest, &'t0 mut SyncResponse),
pub fn add<F, R: ToRegex>(&self, method: Method, path: R, delegate_func: F)where
for<'r, 's, 't0> F: 'static + Fn(&'r C, &'s SyncRequest, &'t0 mut SyncResponse),
Add a delegate function to handle a particular request
Example
let u8_context = 1;
let u8_controller = BasicController::new(u8_context);
u8_controller.add(Method::Get, "^/test$", |ctx, req, res| { println!("this will handle Get request done on <your_host>/test")});
sourcepub fn add_with_guards<F, R: ToRegex>(
&self,
method: Method,
path: R,
guards: RequestGuardCollection,
delegate_func: F
)where
for<'r, 's, 't0> F: 'static + Fn(&'r C, &'s SyncRequest, &'t0 mut SyncResponse),
pub fn add_with_guards<F, R: ToRegex>(
&self,
method: Method,
path: R,
guards: RequestGuardCollection,
delegate_func: F
)where
for<'r, 's, 't0> F: 'static + Fn(&'r C, &'s SyncRequest, &'t0 mut SyncResponse),
Add a delegate function to handle a particular request
Example
let u8_context = 1;
let u8_controller = BasicController::new(u8_context);
u8_controller.add(Method::Get, "^/test$", |ctx, req, res| { println!("this will handle Get request done on <your_host>/test")});
Trait Implementations
sourceimpl<C: Send + Sync> Controller for BasicController<C>
impl<C: Send + Sync> Controller for BasicController<C>
sourcefn handle(&self, req: &mut SyncRequest, res: &mut SyncResponse)
fn handle(&self, req: &mut SyncRequest, res: &mut SyncResponse)
Method invoked if the request gets routed to this controller. Nothing will be processed after a controller
handling
a request.
When returning from this function, the res
param is the response returned to the client. Read moreAuto Trait Implementations
impl<C> !RefUnwindSafe for BasicController<C>
impl<C> Send for BasicController<C>
impl<C> Sync for BasicController<C>
impl<C> Unpin for BasicController<C>where
C: Unpin,
impl<C> !UnwindSafe for BasicController<C>
Blanket Implementations
sourceimpl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more