pub struct StatusCode(/* private fields */);
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<'de> Deserialize<'de> for StatusCode
impl<'de> Deserialize<'de> for StatusCode
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
Deserialize this value from the given Serde deserializer. 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
Source§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 u16
impl PartialEq<StatusCode> for u16
Source§impl PartialEq<u16> for StatusCode
impl PartialEq<u16> for StatusCode
Source§impl PartialEq for StatusCode
impl PartialEq for StatusCode
Source§impl PartialOrd for StatusCode
impl PartialOrd for StatusCode
Source§impl Serialize for StatusCode
impl Serialize for StatusCode
Source§impl<'a> TryFrom<&'a [u8]> for StatusCode
impl<'a> TryFrom<&'a [u8]> for StatusCode
Source§impl<'a> TryFrom<&'a str> for StatusCode
impl<'a> TryFrom<&'a str> for StatusCode
Source§impl TryFrom<u16> for StatusCode
impl TryFrom<u16> for StatusCode
impl Copy for StatusCode
impl Eq for StatusCode
impl StructuralPartialEq for StatusCode
Auto Trait Implementations§
impl Freeze for StatusCode
impl RefUnwindSafe for StatusCode
impl Send for StatusCode
impl Sync for StatusCode
impl Unpin for StatusCode
impl UnwindSafe for StatusCode
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