Struct pavex::blueprint::router::MethodGuard
source · pub struct MethodGuard { /* private fields */ }
Expand description
Used by Blueprint::route
to specify which HTTP methods the route should match.
If you want to match a single HTTP method, use the dedicated constants in this
module (GET
, POST
, PATCH
, DELETE
, etc.).
If you want to match a list of HTTP methods, use either MethodGuard::or
or
MethodGuard::from_iter
.
If you want to match all well-known HTTP methods, use ANY
.
If you want to match any HTTP method, including custom ones, use ANY_WITH_EXTENSIONS
.
Implementations§
source§impl MethodGuard
impl MethodGuard
sourcepub fn from_iter(allowed_methods: impl IntoIterator<Item = Method>) -> Self
pub fn from_iter(allowed_methods: impl IntoIterator<Item = Method>) -> Self
Build a new MethodGuard
that matches incoming requests using the given HTTP methods.
use pavex::blueprint::router::{MethodGuard, GET, POST};
use pavex::http::Method;
// Using an array of methods known at compile-time..
let guard = MethodGuard::from_iter([Method::GET, Method::POST]);
// ..or a dynamic vector, built at runtime.
let guard = MethodGuard::from_iter(vec![Method::GET, Method::PUT]);
// As an alternative, you can use the `or` method to combine two or more `MethodGuard`s.
// It's usually shorter and more readable.
let guard = GET.or(POST);
If you want to match any HTTP method, use ANY
.
If you want to match a single HTTP method, use the dedicated constants in this
module (GET
, POST
, PATCH
, DELETE
, etc.).
sourcepub fn or(self, other: MethodGuard) -> Self
pub fn or(self, other: MethodGuard) -> Self
Combine this MethodGuard
with another one, returning a new MethodGuard
.
The returned MethodGuard
will match requests that match either of the two
MethodGuard
s.
use pavex::blueprint::router::{GET, POST};
// Match requests that use either the `GET` or the `POST` HTTP method.
let guard = GET.or(POST);
sourcepub fn allows(&self, method: &Method) -> bool
pub fn allows(&self, method: &Method) -> bool
Returns true
if the given HTTP method is allowed by this MethodGuard
.
sourcepub fn allowed_methods(&self) -> AllowedMethods
pub fn allowed_methods(&self) -> AllowedMethods
Return the methods allowed by this MethodGuard
.
Trait Implementations§
source§impl Clone for MethodGuard
impl Clone for MethodGuard
source§fn clone(&self) -> MethodGuard
fn clone(&self) -> MethodGuard
1.0.0 · source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read more