Skip to main content

Method

Struct Method 

Source
pub struct Method(/* private fields */);
Expand description

HTTP メソッド (RFC 9110 Section 9.1, method = token)

case-sensitive (RFC 9110 Section 9.1 “The method token is case-sensitive”)。 Eq/Hash も case-sensitive。

§構築経路

用途API不正 token 時
builder ('static リテラル)TryFrom<&'static str> / TryFrom<&'static [u8]>Err(MethodError)
動的入力Method::new()Err(MethodError)
const 定数 (compile-time 拒否)Method::from_static(b"...")コンパイル時 panic

§'static&str について

TryFrom<&'static str> のみ実装しているため、非 'static&str は コンパイルエラーになる。動的な文字列を使う場合は Method::new() で 構築した値を渡すこと。

use shiguredo_http11::Method;

fn make_method(m: &str) -> Method {
    m.try_into().unwrap() // コンパイルエラー: &str は &'static str ではない
}

Implementations§

Source§

impl Method

Source

pub const GET: Self

標準メソッド定数

Source

pub const POST: Self

Source

pub const PUT: Self

Source

pub const DELETE: Self

Source

pub const HEAD: Self

Source

pub const OPTIONS: Self

Source

pub const CONNECT: Self

Source

pub const TRACE: Self

Source

pub const PATCH: Self

Source

pub fn new(method: impl AsRef<[u8]>) -> Result<Self, MethodError>

ランタイム検査つきで構築する

Source

pub const fn from_static(method: &'static [u8]) -> Self

コンパイル時検査つきで構築する

不正な入力はコンパイル時に panic する。 リテラル定数の構築に使用する。

§正常系
use shiguredo_http11::Method;

const GET: Method = Method::from_static(b"GET");
const POST: Method = Method::from_static(b"POST");
const CUSTOM: Method = Method::from_static(b"WebDAV-MOVE");
§不正リテラルの compile-fail 例

空のメソッドは不正:

const _: shiguredo_http11::Method =
    shiguredo_http11::Method::from_static(b"");

CR を含むメソッドは不正:

const _: shiguredo_http11::Method =
    shiguredo_http11::Method::from_static(b"GET\r");

LF を含むメソッドは不正:

const _: shiguredo_http11::Method =
    shiguredo_http11::Method::from_static(b"GET\n");
Source

pub fn as_bytes(&self) -> &[u8]

内部バイト列を返す

Source

pub fn as_str(&self) -> &str

文字列として返す (全 tchar は ASCII のため安全)

Trait Implementations§

Source§

impl Clone for Method

Source§

fn clone(&self) -> Method

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Method

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Display for Method

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl From<Method> for String

Source§

fn from(method: Method) -> Self

Converts to this type from the input type.
Source§

impl Hash for Method

Source§

fn hash<__H: Hasher>(&self, state: &mut __H)

Feeds this value into the given Hasher. Read more
1.3.0 · Source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
Source§

impl PartialEq<&str> for Method

Source§

fn eq(&self, other: &&str) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl PartialEq<Method> for str

Source§

fn eq(&self, other: &Method) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl PartialEq<str> for Method

Source§

fn eq(&self, other: &str) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl PartialEq for Method

Source§

fn eq(&self, other: &Method) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl TryFrom<&'static [u8]> for Method

Source§

type Error = MethodError

The type returned in the event of a conversion error.
Source§

fn try_from(bytes: &'static [u8]) -> Result<Self, Self::Error>

Performs the conversion.
Source§

impl TryFrom<&'static str> for Method

Source§

type Error = MethodError

The type returned in the event of a conversion error.
Source§

fn try_from(s: &'static str) -> Result<Self, Self::Error>

Performs the conversion.
Source§

impl Eq for Method

Source§

impl StructuralPartialEq for Method

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.