pub struct FilterLayer<H, R, T> { /* private fields */ }Available on crate feature
server only.Expand description
Layer for filtering requests
See FilterLayer::new for more details.
Implementations§
Source§impl<H, R, T> FilterLayer<H, R, T>
impl<H, R, T> FilterLayer<H, R, T>
Sourcepub fn new(h: H) -> Self
pub fn new(h: H) -> Self
Create a new FilterLayer
The handler is an async function with some params that implement
FromContext, and returns
Result<(), impl IntoResponse>.
If the handler returns Ok(()), the request will proceed. However, if the handler returns
Err with an object that implements IntoResponse, the request will be rejected with
the returned object as the response.
§Examples
use http::{method::Method, status::StatusCode};
use volo_http::server::{
layer::FilterLayer,
route::{Router, get},
};
async fn reject_post(method: Method) -> Result<(), StatusCode> {
if method == Method::POST {
Err(StatusCode::METHOD_NOT_ALLOWED)
} else {
Ok(())
}
}
async fn handler() -> &'static str {
"Hello, World"
}
let router: Router = Router::new()
.route("/", get(handler))
.layer(FilterLayer::new(reject_post));Trait Implementations§
Source§impl<H: Clone, R: Clone, T: Clone> Clone for FilterLayer<H, R, T>
impl<H: Clone, R: Clone, T: Clone> Clone for FilterLayer<H, R, T>
Source§fn clone(&self) -> FilterLayer<H, R, T>
fn clone(&self) -> FilterLayer<H, R, T>
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, R, T> Layer<S> for FilterLayer<H, R, T>
impl<S, H, R, T> Layer<S> for FilterLayer<H, R, T>
Auto Trait Implementations§
impl<H, R, T> Freeze for FilterLayer<H, R, T>where
H: Freeze,
impl<H, R, T> RefUnwindSafe for FilterLayer<H, R, T>
impl<H, R, T> Send for FilterLayer<H, R, T>
impl<H, R, T> Sync for FilterLayer<H, R, T>
impl<H, R, T> Unpin for FilterLayer<H, R, T>
impl<H, R, T> UnwindSafe for FilterLayer<H, R, T>
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