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 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 moreSource§impl Debug for MethodGuard
impl Debug for MethodGuard
Source§impl<'de> Deserialize<'de> for MethodGuard
impl<'de> Deserialize<'de> for MethodGuard
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
Source§impl From<Method> for MethodGuard
impl From<Method> for MethodGuard
Source§impl FromIterator<Method> for MethodGuard
impl FromIterator<Method> for MethodGuard
Source§fn from_iter<I: IntoIterator<Item = Method>>(allowed_methods: I) -> Self
fn from_iter<I: IntoIterator<Item = Method>>(allowed_methods: I) -> 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.).