Struct salvo_core::Service
source · pub struct Service {
pub router: Arc<Router>,
pub catcher: Option<Arc<Catcher>>,
pub allowed_media_types: Arc<Vec<Mime>>,
}Expand description
Service http request.
Fields§
§router: Arc<Router>The router of this service.
catcher: Option<Arc<Catcher>>The catcher of this service.
allowed_media_types: Arc<Vec<Mime>>The allowed media types of this service.
Implementations§
source§impl Service
impl Service
sourcepub fn new<T>(router: T) -> Servicewhere
T: Into<Arc<Router>>,
pub fn new<T>(router: T) -> Servicewhere T: Into<Arc<Router>>,
Create a new Service with a Router.
sourcepub fn catcher(self, catcher: impl Into<Arc<Catcher>>) -> Self
pub fn catcher(self, catcher: impl Into<Arc<Catcher>>) -> Self
When the response code is 400-600 and the body is empty, capture and set the error page content. If catchers is not set, the default error page will be used.
Example
#[handler]
async fn handle404(&self, _req: &Request, _depot: &Depot, res: &mut Response, ctrl: &mut FlowCtrl) {
if let Some(StatusCode::NOT_FOUND) = res.status_code {
res.render("Custom 404 Error Page");
ctrl.skip_rest();
}
}
#[tokio::main]
async fn main() {
Service::new(Router::new()).catcher(Catcher::default().hoop(handle404));
}Trait Implementations§
Auto Trait Implementations§
impl !RefUnwindSafe for Service
impl Send for Service
impl Sync for Service
impl Unpin for Service
impl !UnwindSafe for Service
Blanket Implementations§
§impl<'a, T, E> AsTaggedExplicit<'a, E> for Twhere
T: 'a,
impl<'a, T, E> AsTaggedExplicit<'a, E> for Twhere T: 'a,
§impl<'a, T, E> AsTaggedImplicit<'a, E> for Twhere
T: 'a,
impl<'a, T, E> AsTaggedImplicit<'a, E> for Twhere T: 'a,
source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more