Struct async_nats::status::StatusCode
source · pub struct StatusCode(_);
Expand description
An NATS status code.
Constants are provided for known status codes.
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.
Examples
use async_nats::StatusCode;
assert_eq!(StatusCode::OK.as_u16(), 200);
assert!(StatusCode::OK.is_success());
Implementations§
source§impl StatusCode
impl StatusCode
sourcepub fn from_u16(src: u16) -> Result<StatusCode, InvalidStatusCode>
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 async_nats::status::StatusCode;
let ok = StatusCode::from_u16(200).unwrap();
assert_eq!(ok, StatusCode::OK);
let err = StatusCode::from_u16(99);
assert!(err.is_err());
let err = StatusCode::from_u16(1000);
assert!(err.is_err());
sourcepub fn from_bytes(src: &[u8]) -> Result<StatusCode, InvalidStatusCode>
pub fn from_bytes(src: &[u8]) -> Result<StatusCode, InvalidStatusCode>
Converts a &[u8]
to a status code
sourcepub fn as_u16(&self) -> u16
pub fn as_u16(&self) -> u16
Returns the u16
corresponding to this StatusCode
.
Example
let status = async_nats::StatusCode::OK;
assert_eq!(status.as_u16(), 200);
sourcepub fn is_informational(&self) -> bool
pub fn is_informational(&self) -> bool
Check if status is within 100-199.
sourcepub fn is_success(&self) -> bool
pub fn is_success(&self) -> bool
Check if status is within 200-299.
sourcepub fn is_redirection(&self) -> bool
pub fn is_redirection(&self) -> bool
Check if status is within 300-399.
sourcepub fn is_client_error(&self) -> bool
pub fn is_client_error(&self) -> bool
Check if status is within 400-499.
sourcepub fn is_server_error(&self) -> bool
pub fn is_server_error(&self) -> bool
Check if status is within 500-599.
source§impl StatusCode
impl StatusCode
pub const IDLE_HEARTBEAT: StatusCode = _
pub const OK: StatusCode = _
pub const NOT_FOUND: StatusCode = _
pub const TIMEOUT: StatusCode = _
pub const NO_RESPONDERS: StatusCode = _
pub const REQUEST_TERMINATED: StatusCode = _
Trait Implementations§
source§impl Clone for StatusCode
impl Clone for StatusCode
source§fn clone(&self) -> StatusCode
fn clone(&self) -> StatusCode
Returns a copy of the value. Read more
1.0.0 · source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source
. Read moresource§impl Debug for StatusCode
impl Debug for StatusCode
source§impl Default for StatusCode
impl Default for StatusCode
source§fn default() -> StatusCode
fn default() -> StatusCode
Returns the “default value” for a type. Read more
source§impl Display for StatusCode
impl Display for StatusCode
source§impl<'a> From<&'a StatusCode> for StatusCode
impl<'a> From<&'a StatusCode> for StatusCode
source§fn from(t: &'a StatusCode) -> Self
fn from(t: &'a StatusCode) -> Self
Converts to this type from the input type.
source§impl From<StatusCode> for u16
impl From<StatusCode> for u16
source§fn from(status: StatusCode) -> u16
fn from(status: StatusCode) -> u16
Converts to this type from the input type.
source§impl FromStr for StatusCode
impl FromStr for StatusCode
§type Err = InvalidStatusCode
type Err = InvalidStatusCode
The associated error which can be returned from parsing.
source§fn from_str(s: &str) -> Result<StatusCode, InvalidStatusCode>
fn from_str(s: &str) -> Result<StatusCode, InvalidStatusCode>
Parses a string
s
to return a value of this type. Read moresource§impl Hash for StatusCode
impl Hash for StatusCode
source§impl Ord for StatusCode
impl Ord for StatusCode
source§fn cmp(&self, other: &StatusCode) -> Ordering
fn cmp(&self, other: &StatusCode) -> Ordering
1.21.0 · source§fn max(self, other: Self) -> Selfwhere
Self: Sized,
fn max(self, other: Self) -> Selfwhere Self: Sized,
Compares and returns the maximum of two values. Read more
source§impl PartialEq<StatusCode> for StatusCode
impl PartialEq<StatusCode> for StatusCode
source§fn eq(&self, other: &StatusCode) -> bool
fn eq(&self, other: &StatusCode) -> bool
This method tests for
self
and other
values to be equal, and is used
by ==
.source§impl PartialEq<StatusCode> for u16
impl PartialEq<StatusCode> for u16
source§fn eq(&self, other: &StatusCode) -> bool
fn eq(&self, other: &StatusCode) -> bool
This method tests for
self
and other
values to be equal, and is used
by ==
.source§impl PartialEq<u16> for StatusCode
impl PartialEq<u16> for StatusCode
source§impl PartialOrd<StatusCode> for StatusCode
impl PartialOrd<StatusCode> for StatusCode
source§fn partial_cmp(&self, other: &StatusCode) -> Option<Ordering>
fn partial_cmp(&self, other: &StatusCode) -> Option<Ordering>
1.0.0 · source§fn le(&self, other: &Rhs) -> bool
fn le(&self, other: &Rhs) -> bool
This method tests less than or equal to (for
self
and other
) and is used by the <=
operator. Read more