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 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
Auto Trait Implementations§
impl Freeze for MethodGuard
impl RefUnwindSafe for MethodGuard
impl Send for MethodGuard
impl Sync for MethodGuard
impl Unpin for MethodGuard
impl UnwindSafe for MethodGuard
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
source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
source§unsafe fn clone_to_uninit(&self, dst: *mut T)
unsafe fn clone_to_uninit(&self, dst: *mut T)
clone_to_uninit
)