Struct saphir::controller::ControllerDispatch
source · pub struct ControllerDispatch<T> { /* private fields */ }
Expand description
Struct to delegate a request to a registered function matching booth a method
and a path
Implementations
sourceimpl<T: Send + Sync> ControllerDispatch<T>
impl<T: Send + Sync> ControllerDispatch<T>
sourcepub fn add<F, R: ToRegex>(&self, method: Method, path: R, delegate_func: F)where
for<'r, 's, 't0> F: 'static + Fn(&'r T, &'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 T, &'s SyncRequest, &'t0 mut SyncResponse),
Add a delegate function to handle a particular request
Example
let u8_context = 1;
let dispatch = ControllerDispatch::new(u8_context);
dispatch.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 T, &'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 T, &'s SyncRequest, &'t0 mut SyncResponse),
Add a delegate function to handle a particular request
Example
let u8_context = 1;
let guard = BodyGuard;
let dispatch = ControllerDispatch::new(u8_context);
dispatch.add_with_guards(Method::Get, "^/test$", guard.into(), |ctx, req, res| { println!("this will handle Get request done on <your_host>/test")});
sourcepub fn dispatch(&self, req: &mut SyncRequest, res: &mut SyncResponse)
pub fn dispatch(&self, req: &mut SyncRequest, res: &mut SyncResponse)
Trait Implementations
impl<T> Send for ControllerDispatch<T>
impl<T> Sync for ControllerDispatch<T>
Auto Trait Implementations
impl<T> !RefUnwindSafe for ControllerDispatch<T>
impl<T> Unpin for ControllerDispatch<T>where
T: Unpin,
impl<T> !UnwindSafe for ControllerDispatch<T>
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