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
impl Method
pub const POST: Self
pub const PUT: Self
pub const DELETE: Self
pub const HEAD: Self
pub const OPTIONS: Self
pub const CONNECT: Self
pub const TRACE: Self
pub const PATCH: Self
Sourcepub const fn from_static(method: &'static [u8]) -> Self
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");Trait Implementations§
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 UnsafeUnpin 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
Mutably borrows from an owned value. Read more