Enum Method
#[non_exhaustive]pub enum Method {
Show 38 variants
Get,
Head,
Post,
Put,
Delete,
Connect,
Options,
Trace,
Patch,
Acl,
BaselineControl,
Bind,
CheckIn,
CheckOut,
Copy,
Label,
Link,
Lock,
Merge,
MkActivity,
MkCalendar,
MkCol,
MkRedirectRef,
MkWorkspace,
Move,
OrderPatch,
PropFind,
PropPatch,
Rebind,
Report,
Search,
Unbind,
Uncheckout,
Unlink,
Unlock,
Update,
UpdateRedirectRef,
VersionControl,
}Expand description
An HTTP method.
Each variant corresponds to a method in the HTTP Method Registry.
The string form of the method can be obtained via
Method::as_str() and parsed via the FromStr or
TryFrom<&[u8]> implementations. The parse implementations parse
both the case-sensitive string form as well as a lowercase version
of the string, but not mixed-case versions.
§(De)Serialization
Method is both Serialize and Deserialize.
Methodserializes as the specification-defined string form of the method, equivalent to the value returned fromMethod::as_str().Methoddeserializes from method’s string form or from a lowercased string, equivalent to theFromStrimplementation.
For example, Method::Get serializes to "GET" and deserializes
from either "GET" or "get" but not "GeT".
use rocket::http::Method;
use rocket::serde::{Serialize, Deserialize};
#[derive(Deserialize, Serialize)]
#[serde(crate = "rocket::serde")]
struct Foo {
method: Method,
}Variants (Non-exhaustive)§
This enum is marked as non-exhaustive
Get
The GET method.
Defined in RFC9110 §9.3.1.
- safe:
yes - idempotent:
yes - request body:
maybe
Head
The HEAD method.
Defined in RFC9110 §9.3.2.
- safe:
yes - idempotent:
yes - request body:
maybe
Post
The POST method.
Defined in RFC9110 §9.3.3.
- safe:
no - idempotent:
no - request body:
yes
Put
The PUT method.
Defined in RFC9110 §9.3.4.
- safe:
no - idempotent:
yes - request body:
yes
Delete
The DELETE method.
Defined in RFC9110 §9.3.5.
- safe:
no - idempotent:
yes - request body:
maybe
Connect
The CONNECT method.
Defined in RFC9110 §9.3.6.
- safe:
no - idempotent:
no - request body:
maybe
Options
The OPTIONS method.
Defined in RFC9110 §9.3.7.
- safe:
yes - idempotent:
yes - request body:
maybe
Trace
The TRACE method.
Defined in RFC9110 §9.3.8.
- safe:
yes - idempotent:
yes - request body:
no
Patch
The PATCH method.
Defined in RFC5789 §2.
- safe:
no - idempotent:
no - request body:
yes
Acl
The ACL method.
Defined in RFC3744 §8.1.
- safe:
no - idempotent:
yes - request body:
yes
BaselineControl
The BASELINE-CONTROL method.
Defined in RFC3253 §12.6.
- safe:
no - idempotent:
yes - request body:
yes
Bind
The BIND method.
Defined in RFC5842 §4.
- safe:
no - idempotent:
yes - request body:
yes
CheckIn
The CHECKIN method.
Defined in RFC3253 §4.4.
- safe:
no - idempotent:
yes - request body:
yes
CheckOut
The CHECKOUT method.
Defined in RFC3253 §4.3.
- safe:
no - idempotent:
yes - request body:
maybe
Copy
The COPY method.
Defined in RFC4918 §9.8.
- safe:
no - idempotent:
yes - request body:
maybe
Label
The LABEL method.
Defined in RFC3253 §8.2.
- safe:
no - idempotent:
yes - request body:
yes
Link
The LINK method.
Defined in RFC2068 §19.6.1.2.
- safe:
no - idempotent:
yes - request body:
maybe
Lock
The LOCK method.
Defined in RFC4918 §9.10.
- safe:
no - idempotent:
no - request body:
yes
Merge
The MERGE method.
Defined in RFC3253 §11.2.
- safe:
no - idempotent:
yes - request body:
yes
MkActivity
The MKACTIVITY method.
Defined in RFC3253 §13.5.
- safe:
no - idempotent:
yes - request body:
yes
MkCalendar
The MKCALENDAR method.
Defined in RFC4791 §5.3.1, RFC8144 §2.3.
- safe:
no - idempotent:
yes - request body:
yes
MkCol
The MKCOL method.
Defined in RFC4918 §9.3, RFC5689 §3, RFC8144 §2.3.
- safe:
no - idempotent:
yes - request body:
yes
MkRedirectRef
The MKREDIRECTREF method.
Defined in RFC4437 §6.
- safe:
no - idempotent:
yes - request body:
yes
MkWorkspace
The MKWORKSPACE method.
Defined in RFC3253 §6.3.
- safe:
no - idempotent:
yes - request body:
yes
Move
The MOVE method.
Defined in RFC4918 §9.9.
- safe:
no - idempotent:
yes - request body:
maybe
OrderPatch
The ORDERPATCH method.
Defined in RFC3648 §7.
- safe:
no - idempotent:
yes - request body:
yes
PropFind
The PROPFIND method.
Defined in RFC4918 §9.1, RFC8144 §2.1.
- safe:
yes - idempotent:
yes - request body:
yes
PropPatch
The PROPPATCH method.
Defined in RFC4918 §9.2, RFC8144 §2.2.
- safe:
no - idempotent:
yes - request body:
yes
Rebind
The REBIND method.
Defined in RFC5842 §6.
- safe:
no - idempotent:
yes - request body:
yes
Report
The REPORT method.
Defined in RFC3253 §3.6, RFC8144 §2.1.
- safe:
yes - idempotent:
yes - request body:
yes
Search
The SEARCH method.
Defined in RFC5323 §2.
- safe:
yes - idempotent:
yes - request body:
yes
Unbind
The UNBIND method.
Defined in RFC5842 §5.
- safe:
no - idempotent:
yes - request body:
yes
Uncheckout
The UNCHECKOUT method.
Defined in RFC3253 §4.5.
- safe:
no - idempotent:
yes - request body:
maybe
Unlink
The UNLINK method.
Defined in RFC2068 §19.6.1.3.
- safe:
no - idempotent:
yes - request body:
maybe
Unlock
The UNLOCK method.
Defined in RFC4918 §9.11.
- safe:
no - idempotent:
yes - request body:
maybe
Update
The UPDATE method.
Defined in RFC3253 §7.1.
- safe:
no - idempotent:
yes - request body:
yes
UpdateRedirectRef
The UPDATEREDIRECTREF method.
Defined in RFC4437 §7.
- safe:
no - idempotent:
yes - request body:
yes
VersionControl
The VERSION-CONTROL method.
Defined in RFC3253 §3.5.
- safe:
no - idempotent:
yes - request body:
yes
Implementations§
§impl Method
impl Method
pub const fn is_safe(&self) -> bool
pub const fn is_safe(&self) -> bool
Whether the method is considered “safe”.
From RFC9110 §9.2.1:
Request methods are considered “safe” if their defined semantics are essentially read-only; i.e., the client does not request, and does not expect, any state change on the origin server as a result of applying a safe method to a target resource. Likewise, reasonable use of a safe method is not expected to cause any harm, loss of property, or unusual burden on the origin server. Of the request methods defined by this specification, the GET, HEAD, OPTIONS, and TRACE methods are defined to be safe.
§Example
use rocket::http::Method;
assert!(Method::Get.is_safe());
assert!(Method::Head.is_safe());
assert!(!Method::Put.is_safe());
assert!(!Method::Post.is_safe());pub const fn is_idempotent(&self) -> bool
pub const fn is_idempotent(&self) -> bool
Whether the method is considered “idempotent”.
From RFC9110 §9.2.2:
A request method is considered “idempotent” if the intended effect on the server of multiple identical requests with that method is the same as the effect for a single such request. Of the request methods defined by this specification, PUT, DELETE, and safe request methods are idempotent.
§Example
use rocket::http::Method;
assert!(Method::Get.is_idempotent());
assert!(Method::Head.is_idempotent());
assert!(Method::Put.is_idempotent());
assert!(!Method::Post.is_idempotent());
assert!(!Method::Patch.is_idempotent());pub const fn allows_request_body(self) -> Option<bool>
pub const fn allows_request_body(self) -> Option<bool>
Whether requests with this method are allowed to have a body.
Returns:
Some(true)if a request body is always allowed.Some(false)if a request body is never allowed.Noneif a request body is discouraged or has no defined semantics.
§Example
use rocket::http::Method;
assert_eq!(Method::Post.allows_request_body(), Some(true));
assert_eq!(Method::Put.allows_request_body(), Some(true));
assert_eq!(Method::Trace.allows_request_body(), Some(false));
assert_eq!(Method::Get.allows_request_body(), None);
assert_eq!(Method::Head.allows_request_body(), None);§impl Method
impl Method
pub const fn supports_payload(self) -> bool
👎Deprecated since 0.6.0: use Self::allows_request_body()
pub const fn supports_payload(self) -> bool
Deprecated. Returns self.allows_request_body() == Some(true).
Use Method::allows_request_body() instead.
Trait Implementations§
§impl<'de> Deserialize<'de> for Method
impl<'de> Deserialize<'de> for Method
§fn deserialize<D>(
deserializer: D,
) -> Result<Method, <D as Deserializer<'de>>::Error>where
D: Deserializer<'de>,
fn deserialize<D>(
deserializer: D,
) -> Result<Method, <D as Deserializer<'de>>::Error>where
D: Deserializer<'de>,
Source§impl<'r> FromRequest<'r> for Method
impl<'r> FromRequest<'r> for Method
Source§type Error = Infallible
type Error = Infallible
§impl Serialize for Method
impl Serialize for Method
§fn serialize<S>(
&self,
serializer: S,
) -> Result<<S as Serializer>::Ok, <S as Serializer>::Error>where
S: Serializer,
fn serialize<S>(
&self,
serializer: S,
) -> Result<<S as Serializer>::Ok, <S as Serializer>::Error>where
S: Serializer,
impl Copy for Method
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> AsAny for Twhere
T: Any,
impl<T> AsAny for Twhere
T: Any,
fn as_any_ref(&self) -> &(dyn Any + 'static)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
Source§impl<'a, T, E> AsTaggedExplicit<'a, E> for Twhere
T: 'a,
impl<'a, T, E> AsTaggedExplicit<'a, E> for Twhere
T: 'a,
Source§impl<'a, T, E> AsTaggedImplicit<'a, E> for Twhere
T: 'a,
impl<'a, T, E> AsTaggedImplicit<'a, E> for Twhere
T: 'a,
Source§impl<T> AsUncased for T
impl<T> AsUncased for T
Source§fn as_uncased(&self) -> &UncasedStr
fn as_uncased(&self) -> &UncasedStr
self to an UncasedStr.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§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key and return true if they are equal.Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
Source§fn in_current_span(self) -> Instrumented<Self> ⓘ
fn in_current_span(self) -> Instrumented<Self> ⓘ
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§impl<T> Paint for Twhere
T: ?Sized,
impl<T> Paint for Twhere
T: ?Sized,
Source§fn fg(&self, value: Color) -> Painted<&T>
fn fg(&self, value: Color) -> Painted<&T>
Returns a styled value derived from self with the foreground set to
value.
This method should be used rarely. Instead, prefer to use color-specific
builder methods like red() and
green(), which have the same functionality but are
pithier.
§Example
Set foreground color to white using fg():
use yansi::{Paint, Color};
painted.fg(Color::White);Set foreground color to white using white().
use yansi::Paint;
painted.white();Source§fn bright_black(&self) -> Painted<&T>
fn bright_black(&self) -> Painted<&T>
Source§fn bright_red(&self) -> Painted<&T>
fn bright_red(&self) -> Painted<&T>
Source§fn bright_green(&self) -> Painted<&T>
fn bright_green(&self) -> Painted<&T>
Source§fn bright_yellow(&self) -> Painted<&T>
fn bright_yellow(&self) -> Painted<&T>
Source§fn bright_blue(&self) -> Painted<&T>
fn bright_blue(&self) -> Painted<&T>
Source§fn bright_magenta(&self) -> Painted<&T>
fn bright_magenta(&self) -> Painted<&T>
Source§fn bright_cyan(&self) -> Painted<&T>
fn bright_cyan(&self) -> Painted<&T>
Source§fn bright_white(&self) -> Painted<&T>
fn bright_white(&self) -> Painted<&T>
Source§fn bg(&self, value: Color) -> Painted<&T>
fn bg(&self, value: Color) -> Painted<&T>
Returns a styled value derived from self with the background set to
value.
This method should be used rarely. Instead, prefer to use color-specific
builder methods like on_red() and
on_green(), which have the same functionality but
are pithier.
§Example
Set background color to red using fg():
use yansi::{Paint, Color};
painted.bg(Color::Red);Set background color to red using on_red().
use yansi::Paint;
painted.on_red();Source§fn on_primary(&self) -> Painted<&T>
fn on_primary(&self) -> Painted<&T>
Source§fn on_magenta(&self) -> Painted<&T>
fn on_magenta(&self) -> Painted<&T>
Source§fn on_bright_black(&self) -> Painted<&T>
fn on_bright_black(&self) -> Painted<&T>
Source§fn on_bright_red(&self) -> Painted<&T>
fn on_bright_red(&self) -> Painted<&T>
Source§fn on_bright_green(&self) -> Painted<&T>
fn on_bright_green(&self) -> Painted<&T>
Source§fn on_bright_yellow(&self) -> Painted<&T>
fn on_bright_yellow(&self) -> Painted<&T>
Source§fn on_bright_blue(&self) -> Painted<&T>
fn on_bright_blue(&self) -> Painted<&T>
Source§fn on_bright_magenta(&self) -> Painted<&T>
fn on_bright_magenta(&self) -> Painted<&T>
Source§fn on_bright_cyan(&self) -> Painted<&T>
fn on_bright_cyan(&self) -> Painted<&T>
Source§fn on_bright_white(&self) -> Painted<&T>
fn on_bright_white(&self) -> Painted<&T>
Source§fn attr(&self, value: Attribute) -> Painted<&T>
fn attr(&self, value: Attribute) -> Painted<&T>
Enables the styling Attribute value.
This method should be used rarely. Instead, prefer to use
attribute-specific builder methods like bold() and
underline(), which have the same functionality
but are pithier.
§Example
Make text bold using attr():
use yansi::{Paint, Attribute};
painted.attr(Attribute::Bold);Make text bold using using bold().
use yansi::Paint;
painted.bold();Source§fn rapid_blink(&self) -> Painted<&T>
fn rapid_blink(&self) -> Painted<&T>
Source§fn quirk(&self, value: Quirk) -> Painted<&T>
fn quirk(&self, value: Quirk) -> Painted<&T>
Enables the yansi Quirk value.
This method should be used rarely. Instead, prefer to use quirk-specific
builder methods like mask() and
wrap(), which have the same functionality but are
pithier.
§Example
Enable wrapping using .quirk():
use yansi::{Paint, Quirk};
painted.quirk(Quirk::Wrap);Enable wrapping using wrap().
use yansi::Paint;
painted.wrap();Source§fn clear(&self) -> Painted<&T>
👎Deprecated since 1.0.1: renamed to resetting() due to conflicts with Vec::clear().
The clear() method will be removed in a future release.
fn clear(&self) -> Painted<&T>
resetting() due to conflicts with Vec::clear().
The clear() method will be removed in a future release.Source§fn whenever(&self, value: Condition) -> Painted<&T>
fn whenever(&self, value: Condition) -> Painted<&T>
Conditionally enable styling based on whether the Condition value
applies. Replaces any previous condition.
See the crate level docs for more details.
§Example
Enable styling painted only when both stdout and stderr are TTYs:
use yansi::{Paint, Condition};
painted.red().on_yellow().whenever(Condition::STDOUTERR_ARE_TTY);