Struct StatusCode

pub struct StatusCode(/* private fields */);
Available on crate feature dep_ureq only.
Expand description

An HTTP status code (status-code in RFC 9110 et al.).

Constants are provided for known status codes, including those in the IANA HTTP Status Code Registry.

Status code values in the range 100-999 (inclusive) are supported by this type. Values in the range 100-599 are semantically classified by the most significant digit. See StatusCode::is_success, etc. Values above 599 are unclassified but allowed for legacy compatibility, though their use is discouraged. Applications may interpret such values as protocol errors.

§Examples

use http::StatusCode;

assert_eq!(StatusCode::from_u16(200).unwrap(), StatusCode::OK);
assert_eq!(StatusCode::NOT_FOUND.as_u16(), 404);
assert!(StatusCode::OK.is_success());

Implementations§

§

impl StatusCode

pub fn from_u16(src: u16) -> Result<StatusCode, InvalidStatusCode>

Converts a u16 to a status code.

The function validates the correctness of the supplied u16. It must be greater or equal to 100 and less than 1000.

§Example
use http::StatusCode;

let ok = StatusCode::from_u16(200).unwrap();
assert_eq!(ok, StatusCode::OK);

let err = StatusCode::from_u16(99);
assert!(err.is_err());

pub fn from_bytes(src: &[u8]) -> Result<StatusCode, InvalidStatusCode>

Converts a &u8 to a status code

pub const fn as_u16(&self) -> u16

Returns the u16 corresponding to this StatusCode.

§Note

This is the same as the From<StatusCode> implementation, but included as an inherent method because that implementation doesn’t appear in rustdocs, as well as a way to force the type instead of relying on inference.

§Example
let status = http::StatusCode::OK;
assert_eq!(status.as_u16(), 200);

pub fn as_str(&self) -> &str

Returns a &str representation of the StatusCode

The return value only includes a numerical representation of the status code. The canonical reason is not included.

§Example
let status = http::StatusCode::OK;
assert_eq!(status.as_str(), "200");

pub fn canonical_reason(&self) -> Option<&'static str>

Get the standardised reason-phrase for this status code.

This is mostly here for servers writing responses, but could potentially have application at other times.

The reason phrase is defined as being exclusively for human readers. You should avoid deriving any meaning from it at all costs.

Bear in mind also that in HTTP/2.0 and HTTP/3.0 the reason phrase is abolished from transmission, and so this canonical reason phrase really is the only reason phrase you’ll find.

§Example
let status = http::StatusCode::OK;
assert_eq!(status.canonical_reason(), Some("OK"));

pub fn is_informational(&self) -> bool

Check if status is within 100-199.

pub fn is_success(&self) -> bool

Check if status is within 200-299.

pub fn is_redirection(&self) -> bool

Check if status is within 300-399.

pub fn is_client_error(&self) -> bool

Check if status is within 400-499.

pub fn is_server_error(&self) -> bool

Check if status is within 500-599.

§

impl StatusCode

pub const CONTINUE: StatusCode

100 Continue [RFC9110, Section 15.2.1]

pub const SWITCHING_PROTOCOLS: StatusCode

101 Switching Protocols [RFC9110, Section 15.2.2]

pub const PROCESSING: StatusCode

102 Processing [RFC2518, Section 10.1]

pub const OK: StatusCode

pub const CREATED: StatusCode

pub const ACCEPTED: StatusCode

202 Accepted [RFC9110, Section 15.3.3]

pub const NON_AUTHORITATIVE_INFORMATION: StatusCode

203 Non-Authoritative Information [RFC9110, Section 15.3.4]

pub const NO_CONTENT: StatusCode

204 No Content [RFC9110, Section 15.3.5]

pub const RESET_CONTENT: StatusCode

205 Reset Content [RFC9110, Section 15.3.6]

pub const PARTIAL_CONTENT: StatusCode

206 Partial Content [RFC9110, Section 15.3.7]

pub const MULTI_STATUS: StatusCode

207 Multi-Status [RFC4918, Section 11.1]

pub const ALREADY_REPORTED: StatusCode

208 Already Reported [RFC5842, Section 7.1]

pub const IM_USED: StatusCode

pub const MULTIPLE_CHOICES: StatusCode

300 Multiple Choices [RFC9110, Section 15.4.1]

pub const MOVED_PERMANENTLY: StatusCode

301 Moved Permanently [RFC9110, Section 15.4.2]

pub const FOUND: StatusCode

pub const SEE_OTHER: StatusCode

303 See Other [RFC9110, Section 15.4.4]

pub const NOT_MODIFIED: StatusCode

304 Not Modified [RFC9110, Section 15.4.5]

pub const USE_PROXY: StatusCode

305 Use Proxy [RFC9110, Section 15.4.6]

pub const TEMPORARY_REDIRECT: StatusCode

307 Temporary Redirect [RFC9110, Section 15.4.7]

pub const PERMANENT_REDIRECT: StatusCode

308 Permanent Redirect [RFC9110, Section 15.4.8]

pub const BAD_REQUEST: StatusCode

400 Bad Request [RFC9110, Section 15.5.1]

pub const UNAUTHORIZED: StatusCode

401 Unauthorized [RFC9110, Section 15.5.2]

pub const PAYMENT_REQUIRED: StatusCode

402 Payment Required [RFC9110, Section 15.5.3]

pub const FORBIDDEN: StatusCode

403 Forbidden [RFC9110, Section 15.5.4]

pub const NOT_FOUND: StatusCode

404 Not Found [RFC9110, Section 15.5.5]

pub const METHOD_NOT_ALLOWED: StatusCode

405 Method Not Allowed [RFC9110, Section 15.5.6]

pub const NOT_ACCEPTABLE: StatusCode

406 Not Acceptable [RFC9110, Section 15.5.7]

pub const PROXY_AUTHENTICATION_REQUIRED: StatusCode

407 Proxy Authentication Required [RFC9110, Section 15.5.8]

pub const REQUEST_TIMEOUT: StatusCode

408 Request Timeout [RFC9110, Section 15.5.9]

pub const CONFLICT: StatusCode

409 Conflict [RFC9110, Section 15.5.10]

pub const GONE: StatusCode

pub const LENGTH_REQUIRED: StatusCode

411 Length Required [RFC9110, Section 15.5.12]

pub const PRECONDITION_FAILED: StatusCode

412 Precondition Failed [RFC9110, Section 15.5.13]

pub const PAYLOAD_TOO_LARGE: StatusCode

413 Payload Too Large [RFC9110, Section 15.5.14]

pub const URI_TOO_LONG: StatusCode

414 URI Too Long [RFC9110, Section 15.5.15]

pub const UNSUPPORTED_MEDIA_TYPE: StatusCode

415 Unsupported Media Type [RFC9110, Section 15.5.16]

pub const RANGE_NOT_SATISFIABLE: StatusCode

416 Range Not Satisfiable [RFC9110, Section 15.5.17]

pub const EXPECTATION_FAILED: StatusCode

417 Expectation Failed [RFC9110, Section 15.5.18]

pub const IM_A_TEAPOT: StatusCode

418 I’m a teapot [curiously not registered by IANA but RFC2324, Section 2.3.2]

pub const MISDIRECTED_REQUEST: StatusCode

421 Misdirected Request [RFC9110, Section 15.5.20]

pub const UNPROCESSABLE_ENTITY: StatusCode

422 Unprocessable Entity [RFC9110, Section 15.5.21]

pub const LOCKED: StatusCode

423 Locked [RFC4918, Section 11.3]

pub const FAILED_DEPENDENCY: StatusCode

424 Failed Dependency [RFC4918, Section 11.4]

pub const TOO_EARLY: StatusCode

425 Too early [RFC8470, Section 5.2]

pub const UPGRADE_REQUIRED: StatusCode

426 Upgrade Required [RFC9110, Section 15.5.22]

pub const PRECONDITION_REQUIRED: StatusCode

428 Precondition Required [RFC6585, Section 3]

pub const TOO_MANY_REQUESTS: StatusCode

429 Too Many Requests [RFC6585, Section 4]

pub const REQUEST_HEADER_FIELDS_TOO_LARGE: StatusCode

431 Request Header Fields Too Large [RFC6585, Section 5]

451 Unavailable For Legal Reasons [RFC7725, Section 3]

pub const INTERNAL_SERVER_ERROR: StatusCode

500 Internal Server Error [RFC9110, Section 15.6.1]

pub const NOT_IMPLEMENTED: StatusCode

501 Not Implemented [RFC9110, Section 15.6.2]

pub const BAD_GATEWAY: StatusCode

502 Bad Gateway [RFC9110, Section 15.6.3]

pub const SERVICE_UNAVAILABLE: StatusCode

503 Service Unavailable [RFC9110, Section 15.6.4]

pub const GATEWAY_TIMEOUT: StatusCode

504 Gateway Timeout [RFC9110, Section 15.6.5]

pub const HTTP_VERSION_NOT_SUPPORTED: StatusCode

505 HTTP Version Not Supported [RFC9110, Section 15.6.6]

pub const VARIANT_ALSO_NEGOTIATES: StatusCode

506 Variant Also Negotiates [RFC2295, Section 8.1]

pub const INSUFFICIENT_STORAGE: StatusCode

507 Insufficient Storage [RFC4918, Section 11.5]

pub const LOOP_DETECTED: StatusCode

508 Loop Detected [RFC5842, Section 7.2]

pub const NOT_EXTENDED: StatusCode

510 Not Extended [RFC2774, Section 7]

pub const NETWORK_AUTHENTICATION_REQUIRED: StatusCode

511 Network Authentication Required [RFC6585, Section 6]

Trait Implementations§

§

impl Clone for StatusCode

§

fn clone(&self) -> StatusCode

Returns a copy of the value. Read more
1.0.0 · Source§

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

Performs copy-assignment from source. Read more
§

impl Debug for StatusCode

§

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

Formats the value using the given formatter. Read more
§

impl Default for StatusCode

§

fn default() -> StatusCode

Returns the “default value” for a type. Read more
§

impl Display for StatusCode

Formats the status code, including the canonical reason.

§Example

assert_eq!(format!("{}", StatusCode::OK), "200 OK");
§

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

Formats the value using the given formatter. Read more
§

impl<'a> From<&'a StatusCode> for StatusCode

§

fn from(t: &'a StatusCode) -> StatusCode

Converts to this type from the input type.
§

impl From<StatusCode> for u16

§

fn from(status: StatusCode) -> u16

Converts to this type from the input type.
§

impl FromStr for StatusCode

§

type Err = InvalidStatusCode

The associated error which can be returned from parsing.
§

fn from_str(s: &str) -> Result<StatusCode, InvalidStatusCode>

Parses a string s to return a value of this type. Read more
§

impl Hash for StatusCode

§

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

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
§

impl Ord for StatusCode

§

fn cmp(&self, other: &StatusCode) -> Ordering

This method returns an Ordering between self and other. Read more
1.21.0 · Source§

fn max(self, other: Self) -> Self
where Self: Sized,

Compares and returns the maximum of two values. Read more
1.21.0 · Source§

fn min(self, other: Self) -> Self
where Self: Sized,

Compares and returns the minimum of two values. Read more
1.50.0 · Source§

fn clamp(self, min: Self, max: Self) -> Self
where Self: Sized,

Restrict a value to a certain interval. Read more
§

impl PartialEq<StatusCode> for u16

§

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

Tests for self and other values to be equal, and is used by ==.
1.0.0 · 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.
§

impl PartialEq<u16> for StatusCode

§

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

Tests for self and other values to be equal, and is used by ==.
1.0.0 · 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.
§

impl PartialEq for StatusCode

§

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

Tests for self and other values to be equal, and is used by ==.
1.0.0 · 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.
§

impl PartialOrd for StatusCode

§

fn partial_cmp(&self, other: &StatusCode) -> Option<Ordering>

This method returns an ordering between self and other values if one exists. Read more
1.0.0 · Source§

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

Tests less than (for self and other) and is used by the < operator. Read more
1.0.0 · Source§

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

Tests less than or equal to (for self and other) and is used by the <= operator. Read more
1.0.0 · Source§

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

Tests greater than (for self and other) and is used by the > operator. Read more
1.0.0 · Source§

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

Tests greater than or equal to (for self and other) and is used by the >= operator. Read more
§

impl<'a> TryFrom<&'a [u8]> for StatusCode

§

type Error = InvalidStatusCode

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

fn try_from( t: &'a [u8], ) -> Result<StatusCode, <StatusCode as TryFrom<&'a [u8]>>::Error>

Performs the conversion.
§

impl<'a> TryFrom<&'a str> for StatusCode

§

type Error = InvalidStatusCode

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

fn try_from( t: &'a str, ) -> Result<StatusCode, <StatusCode as TryFrom<&'a str>>::Error>

Performs the conversion.
§

impl TryFrom<u16> for StatusCode

§

type Error = InvalidStatusCode

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

fn try_from(t: u16) -> Result<StatusCode, <StatusCode as TryFrom<u16>>::Error>

Performs the conversion.
§

impl Copy for StatusCode

§

impl Eq for StatusCode

§

impl StructuralPartialEq for StatusCode

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> ByteSized for T

Source§

const BYTE_ALIGN: usize = _

The alignment of this type in bytes.
Source§

const BYTE_SIZE: usize = _

The size of this type in bytes.
Source§

fn byte_align(&self) -> usize

Returns the alignment of this type in bytes.
Source§

fn byte_size(&self) -> usize

Returns the size of this type in bytes. Read more
Source§

fn ptr_size_ratio(&self) -> [usize; 2]

Returns the size ratio between Ptr::BYTES and BYTE_SIZE. Read more
Source§

impl<T, R> Chain<R> for T
where T: ?Sized,

Source§

fn chain<F>(self, f: F) -> R
where F: FnOnce(Self) -> R, Self: Sized,

Chain a function which takes the parameter by value.
Source§

fn chain_ref<F>(&self, f: F) -> R
where F: FnOnce(&Self) -> R,

Chain a function which takes the parameter by shared reference.
Source§

fn chain_mut<F>(&mut self, f: F) -> R
where F: FnOnce(&mut Self) -> R,

Chain a function which takes the parameter by exclusive reference.
Source§

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

Source§

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

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

impl<Q, K> Comparable<K> for Q
where Q: Ord + ?Sized, K: Borrow<Q> + ?Sized,

§

fn compare(&self, key: &K) -> Ordering

Compare self to key and return their ordering.
§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

§

fn equivalent(&self, key: &K) -> bool

Compare self to key and return true if they are equal.
Source§

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

Source§

fn type_id() -> TypeId

Returns the TypeId of Self. Read more
Source§

fn type_of(&self) -> TypeId

Returns the TypeId of self. Read more
Source§

fn type_name(&self) -> &'static str

Returns the type name of self. Read more
Source§

fn type_is<T: 'static>(&self) -> bool

Returns true if Self is of type T. Read more
Source§

fn type_hash(&self) -> u64

Returns a deterministic hash of the TypeId of Self.
Source§

fn type_hash_with<H: Hasher>(&self, hasher: H) -> u64

Returns a deterministic hash of the TypeId of Self using a custom hasher.
Source§

fn as_any_ref(&self) -> &dyn Any
where Self: Sized,

Upcasts &self as &dyn Any. Read more
Source§

fn as_any_mut(&mut self) -> &mut dyn Any
where Self: Sized,

Upcasts &mut self as &mut dyn Any. Read more
Source§

fn as_any_box(self: Box<Self>) -> Box<dyn Any>
where Self: Sized,

Upcasts Box<self> as Box<dyn Any>. Read more
Source§

fn downcast_ref<T: 'static>(&self) -> Option<&T>

Available on crate feature unsafe_layout only.
Returns some shared reference to the inner value if it is of type T. Read more
Source§

fn downcast_mut<T: 'static>(&mut self) -> Option<&mut T>

Available on crate feature unsafe_layout only.
Returns some exclusive reference to the inner value if it is of type T. Read more
Source§

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

Source§

const NEEDS_DROP: bool = _

Know whether dropping values of this type matters, in compile-time.
Source§

fn mem_align_of<T>() -> usize

Returns the minimum alignment of the type in bytes. Read more
Source§

fn mem_align_of_val(&self) -> usize

Returns the alignment of the pointed-to value in bytes. Read more
Source§

fn mem_size_of<T>() -> usize

Returns the size of a type in bytes. Read more
Source§

fn mem_size_of_val(&self) -> usize

Returns the size of the pointed-to value in bytes. Read more
Source§

fn mem_copy(&self) -> Self
where Self: Copy,

Bitwise-copies a value. Read more
Source§

fn mem_needs_drop(&self) -> bool

Returns true if dropping values of this type matters. Read more
Source§

fn mem_drop(self)
where Self: Sized,

Drops self by running its destructor. Read more
Source§

fn mem_forget(self)
where Self: Sized,

Forgets about self without running its destructor. Read more
Source§

fn mem_replace(&mut self, other: Self) -> Self
where Self: Sized,

Replaces self with other, returning the previous value of self. Read more
Source§

fn mem_take(&mut self) -> Self
where Self: Default,

Replaces self with its default value, returning the previous value of self. Read more
Source§

fn mem_swap(&mut self, other: &mut Self)
where Self: Sized,

Swaps the value of self and other without deinitializing either one. Read more
Source§

unsafe fn mem_zeroed<T>() -> T

Available on crate feature unsafe_layout only.
Returns the value of type T represented by the all-zero byte-pattern. Read more
Source§

unsafe fn mem_transmute_copy<Src, Dst>(src: &Src) -> Dst

Available on crate feature unsafe_layout only.
Returns the value of type T represented by the all-zero byte-pattern. Read more
Source§

fn mem_as_bytes(&self) -> &[u8]
where Self: Sync + Unpin,

Available on crate feature unsafe_slice only.
View a Sync + Unpin self as &[u8]. Read more
Source§

fn mem_as_bytes_mut(&mut self) -> &mut [u8]
where Self: Sync + Unpin,

Available on crate feature unsafe_slice only.
View a Sync + Unpin self as &mut [u8]. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

§

impl<S> FromSample<S> for S

§

fn from_sample_(s: S) -> S

Source§

impl<T> Hook for T

Source§

fn hook_ref<F>(self, f: F) -> Self
where F: FnOnce(&Self),

Applies a function which takes the parameter by shared reference, and then returns the (possibly) modified owned value. Read more
Source§

fn hook_mut<F>(self, f: F) -> Self
where F: FnOnce(&mut Self),

Applies a function which takes the parameter by exclusive reference, and then returns the (possibly) modified owned value. Read more
§

impl<T> Instrument for T

§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts 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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts 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 more
§

impl<F, T> IntoSample<T> for F
where T: FromSample<F>,

§

fn into_sample(self) -> T

§

impl<T> Pointable for T

§

const ALIGN: usize

The alignment of pointer.
§

type Init = T

The type for initializers.
§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
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
§

impl<T, U> ToSample<U> for T
where U: FromSample<T>,

§

fn to_sample_(self) -> U

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.
§

impl<T> WithSubscriber for T

§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more
§

impl<S, T> Duplex<S> for T
where T: FromSample<S> + ToSample<S>,

§

impl<T> Ungil for T
where T: Send,