Struct Method
pub struct Method(/* private fields */);
Expand description
The Request Method (VERB)
This type also contains constants for a number of common HTTP methods such as GET, POST, etc.
Currently includes 8 variants representing the 8 methods defined in RFC 7230, plus PATCH, and an Extension variant for all extensions.
§Examples
use http::Method;
assert_eq!(Method::GET, Method::from_bytes(b"GET").unwrap());
assert!(Method::GET.is_idempotent());
assert_eq!(Method::POST.as_str(), "POST");
Implementations§
§impl Method
impl Method
pub fn from_bytes(src: &[u8]) -> Result<Method, InvalidMethod>
pub fn from_bytes(src: &[u8]) -> Result<Method, InvalidMethod>
Converts a slice of bytes to an HTTP method.
pub fn is_safe(&self) -> bool
pub fn is_safe(&self) -> bool
Whether a method is considered “safe”, meaning the request is essentially read-only.
See the spec for more words.
pub fn is_idempotent(&self) -> bool
pub fn is_idempotent(&self) -> bool
Whether a method is considered “idempotent”, meaning the request has the same result if executed multiple times.
See the spec for more words.
Trait Implementations§
Source§impl From<Method> for MethodGuard
impl From<Method> for MethodGuard
Source§impl FromIterator<Method> for MethodAllowList
impl FromIterator<Method> for MethodAllowList
Source§fn from_iter<I: IntoIterator<Item = Method>>(iter: I) -> Self
fn from_iter<I: IntoIterator<Item = Method>>(iter: I) -> Self
Create a new instance of MethodAllowList
from an iterator
that yields Method
s.
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.).
impl Eq for Method
impl StructuralPartialEq for Method
Auto Trait Implementations§
impl Freeze for Method
impl RefUnwindSafe for Method
impl Send for Method
impl Sync for Method
impl Unpin for Method
impl UnwindSafe for Method
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,
§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key
and return true
if they are equal.