Struct tauri::http::status::StatusCode

source ·
pub struct StatusCode(_);
Expand description

An HTTP status code (status-code in RFC 7230 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§

Available on crate feature http-api only.

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());
Available on crate feature http-api only.

Converts a &u8 to a status code

Available on crate feature http-api only.

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);
Available on crate feature http-api only.

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");
Available on crate feature http-api only.

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"));
Available on crate feature http-api only.

Check if status is within 100-199.

Available on crate feature http-api only.

Check if status is within 200-299.

Available on crate feature http-api only.

Check if status is within 300-399.

Available on crate feature http-api only.

Check if status is within 400-499.

Available on crate feature http-api only.

Check if status is within 500-599.

Available on crate feature http-api only.

100 Continue [RFC7231, Section 6.2.1]

Available on crate feature http-api only.

101 Switching Protocols [RFC7231, Section 6.2.2]

Available on crate feature http-api only.

102 Processing [RFC2518]

Available on crate feature http-api only.
Available on crate feature http-api only.

201 Created [RFC7231, Section 6.3.2]

Available on crate feature http-api only.

202 Accepted [RFC7231, Section 6.3.3]

Available on crate feature http-api only.

203 Non-Authoritative Information [RFC7231, Section 6.3.4]

Available on crate feature http-api only.

204 No Content [RFC7231, Section 6.3.5]

Available on crate feature http-api only.

205 Reset Content [RFC7231, Section 6.3.6]

Available on crate feature http-api only.

206 Partial Content [RFC7233, Section 4.1]

Available on crate feature http-api only.

207 Multi-Status [RFC4918]

Available on crate feature http-api only.

208 Already Reported [RFC5842]

Available on crate feature http-api only.

226 IM Used [RFC3229]

Available on crate feature http-api only.

300 Multiple Choices [RFC7231, Section 6.4.1]

Available on crate feature http-api only.

301 Moved Permanently [RFC7231, Section 6.4.2]

Available on crate feature http-api only.
Available on crate feature http-api only.

303 See Other [RFC7231, Section 6.4.4]

Available on crate feature http-api only.

304 Not Modified [RFC7232, Section 4.1]

Available on crate feature http-api only.

305 Use Proxy [RFC7231, Section 6.4.5]

Available on crate feature http-api only.

307 Temporary Redirect [RFC7231, Section 6.4.7]

Available on crate feature http-api only.

308 Permanent Redirect [RFC7238]

Available on crate feature http-api only.

400 Bad Request [RFC7231, Section 6.5.1]

Available on crate feature http-api only.

401 Unauthorized [RFC7235, Section 3.1]

Available on crate feature http-api only.

402 Payment Required [RFC7231, Section 6.5.2]

Available on crate feature http-api only.

403 Forbidden [RFC7231, Section 6.5.3]

Available on crate feature http-api only.

404 Not Found [RFC7231, Section 6.5.4]

Available on crate feature http-api only.

405 Method Not Allowed [RFC7231, Section 6.5.5]

Available on crate feature http-api only.

406 Not Acceptable [RFC7231, Section 6.5.6]

Available on crate feature http-api only.

407 Proxy Authentication Required [RFC7235, Section 3.2]

Available on crate feature http-api only.

408 Request Timeout [RFC7231, Section 6.5.7]

Available on crate feature http-api only.

409 Conflict [RFC7231, Section 6.5.8]

Available on crate feature http-api only.
Available on crate feature http-api only.

411 Length Required [RFC7231, Section 6.5.10]

Available on crate feature http-api only.

412 Precondition Failed [RFC7232, Section 4.2]

Available on crate feature http-api only.

413 Payload Too Large [RFC7231, Section 6.5.11]

Available on crate feature http-api only.

414 URI Too Long [RFC7231, Section 6.5.12]

Available on crate feature http-api only.

415 Unsupported Media Type [RFC7231, Section 6.5.13]

Available on crate feature http-api only.

416 Range Not Satisfiable [RFC7233, Section 4.4]

Available on crate feature http-api only.

417 Expectation Failed [RFC7231, Section 6.5.14]

Available on crate feature http-api only.

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

Available on crate feature http-api only.

421 Misdirected Request RFC7540, Section 9.1.2

Available on crate feature http-api only.

422 Unprocessable Entity [RFC4918]

Available on crate feature http-api only.

423 Locked [RFC4918]

Available on crate feature http-api only.

424 Failed Dependency [RFC4918]

Available on crate feature http-api only.

426 Upgrade Required [RFC7231, Section 6.5.15]

Available on crate feature http-api only.

428 Precondition Required [RFC6585]

Available on crate feature http-api only.

429 Too Many Requests [RFC6585]

Available on crate feature http-api only.

431 Request Header Fields Too Large [RFC6585]

Available on crate feature http-api only.

451 Unavailable For Legal Reasons [RFC7725]

Available on crate feature http-api only.

500 Internal Server Error [RFC7231, Section 6.6.1]

Available on crate feature http-api only.

501 Not Implemented [RFC7231, Section 6.6.2]

Available on crate feature http-api only.

502 Bad Gateway [RFC7231, Section 6.6.3]

Available on crate feature http-api only.

503 Service Unavailable [RFC7231, Section 6.6.4]

Available on crate feature http-api only.

504 Gateway Timeout [RFC7231, Section 6.6.5]

Available on crate feature http-api only.

505 HTTP Version Not Supported [RFC7231, Section 6.6.6]

Available on crate feature http-api only.

506 Variant Also Negotiates [RFC2295]

Available on crate feature http-api only.

507 Insufficient Storage [RFC4918]

Available on crate feature http-api only.

508 Loop Detected [RFC5842]

Available on crate feature http-api only.

510 Not Extended [RFC2774]

Available on crate feature http-api only.

511 Network Authentication Required [RFC6585]

Trait Implementations§

Returns a copy of the value. Read more
Performs copy-assignment from source. Read more
Formats the value using the given formatter. Read more
Returns the “default value” for a type. Read more

Formats the status code, including the canonical reason.

Example

assert_eq!(format!("{}", StatusCode::OK), "200 OK");
Formats the value using the given formatter. Read more
Converts to this type from the input type.
The associated error which can be returned from parsing.
Parses a string s to return a value of this type. Read more
Feeds this value into the given Hasher. Read more
Feeds a slice of this type into the given Hasher. Read more
This method returns an Ordering between self and other. Read more
Compares and returns the maximum of two values. Read more
Compares and returns the minimum of two values. Read more
Restrict a value to a certain interval. Read more
This method tests for self and other values to be equal, and is used by ==. Read more
This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason. Read more
This method tests for self and other values to be equal, and is used by ==. Read more
This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason. Read more
This method returns an ordering between self and other values if one exists. Read more
This method tests less than (for self and other) and is used by the < operator. Read more
This method tests less than or equal to (for self and other) and is used by the <= operator. Read more
This method tests greater than (for self and other) and is used by the > operator. Read more
This method tests greater than or equal to (for self and other) and is used by the >= operator. Read more
The type returned in the event of a conversion error.
Performs the conversion.
The type returned in the event of a conversion error.
Performs the conversion.
The type returned in the event of a conversion error.
Performs the conversion.

Auto Trait Implementations§

Blanket Implementations§

Gets the TypeId of self. Read more
Immutably borrows from an owned value. Read more
Mutably borrows from an owned value. Read more
Compare self to key and return true if they are equal.

Returns the argument unchanged.

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

Calls U::from(self).

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

The resulting type after obtaining ownership.
Creates owned data from borrowed data, usually by cloning. Read more
Uses borrowed data to replace owned data, usually by cloning. Read more
Converts the given value to a String. Read more
The type returned in the event of a conversion error.
Performs the conversion.
The type returned in the event of a conversion error.
Performs the conversion.
Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more