pub struct TimeoutLayer<H> { /* private fields */ }Available on crate feature
server only.Expand description
Layer for setting timeout to the request
See TimeoutLayer::new for more details.
Implementations§
Source§impl<H> TimeoutLayer<H>
impl<H> TimeoutLayer<H>
Sourcepub fn new(duration: Duration, handler: H) -> Self
pub fn new(duration: Duration, handler: H) -> Self
Create a new TimeoutLayer with given Duration and handler.
The handler should be a sync function with &ServerContext as parameter,
and return anything that implement IntoResponse.
§Examples
use std::time::Duration;
use http::status::StatusCode;
use volo_http::{
context::ServerContext,
server::{
layer::TimeoutLayer,
route::{Router, get},
},
};
async fn index() -> &'static str {
"Hello, World"
}
fn timeout_handler(_: &ServerContext) -> StatusCode {
StatusCode::REQUEST_TIMEOUT
}
let router: Router = Router::new()
.route("/", get(index))
.layer(TimeoutLayer::new(Duration::from_secs(1), timeout_handler));Trait Implementations§
Source§impl<H: Clone> Clone for TimeoutLayer<H>
impl<H: Clone> Clone for TimeoutLayer<H>
Source§fn clone(&self) -> TimeoutLayer<H>
fn clone(&self) -> TimeoutLayer<H>
Returns a duplicate of the value. Read more
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreSource§impl<S, H> Layer<S> for TimeoutLayer<H>
impl<S, H> Layer<S> for TimeoutLayer<H>
Auto Trait Implementations§
impl<H> Freeze for TimeoutLayer<H>where
H: Freeze,
impl<H> RefUnwindSafe for TimeoutLayer<H>where
H: RefUnwindSafe,
impl<H> Send for TimeoutLayer<H>where
H: Send,
impl<H> Sync for TimeoutLayer<H>where
H: Sync,
impl<H> Unpin for TimeoutLayer<H>where
H: Unpin,
impl<H> UnwindSafe for TimeoutLayer<H>where
H: UnwindSafe,
Blanket Implementations§
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