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
sourceimpl 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.
sourceimpl StatusCode
impl StatusCode
pub const IDLE_HEARBEAT: StatusCode = _
pub const OK: StatusCode = _
pub const NOT_FOUND: StatusCode = _
pub const TIMEOUT: StatusCode = _
pub const NO_RESPONDERS: StatusCode = _
Trait Implementations
sourceimpl Clone for StatusCode
impl Clone for StatusCode
sourcefn clone(&self) -> StatusCode
fn clone(&self) -> StatusCode
Returns a copy of the value. Read more
1.0.0 · sourcefn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from source
. Read more
sourceimpl Debug for StatusCode
impl Debug for StatusCode
sourceimpl Default for StatusCode
impl Default for StatusCode
sourcefn default() -> StatusCode
fn default() -> StatusCode
Returns the “default value” for a type. Read more
sourceimpl Display for StatusCode
impl Display for StatusCode
sourceimpl<'a> From<&'a StatusCode> for StatusCode
impl<'a> From<&'a StatusCode> for StatusCode
sourcefn from(t: &'a StatusCode) -> Self
fn from(t: &'a StatusCode) -> Self
Converts to this type from the input type.
sourceimpl From<StatusCode> for u16
impl From<StatusCode> for u16
sourcefn from(status: StatusCode) -> u16
fn from(status: StatusCode) -> u16
Converts to this type from the input type.
sourceimpl FromStr for StatusCode
impl FromStr for StatusCode
type Err = InvalidStatusCode
type Err = InvalidStatusCode
The associated error which can be returned from parsing.
sourcefn 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 more
sourceimpl Hash for StatusCode
impl Hash for StatusCode
sourceimpl Ord for StatusCode
impl Ord for StatusCode
sourceimpl PartialEq<StatusCode> for StatusCode
impl PartialEq<StatusCode> for StatusCode
sourcefn 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 ==
. Read more
sourcefn ne(&self, other: &StatusCode) -> bool
fn ne(&self, other: &StatusCode) -> bool
This method tests for !=
.
sourceimpl PartialEq<StatusCode> for u16
impl PartialEq<StatusCode> for u16
sourceimpl PartialEq<u16> for StatusCode
impl PartialEq<u16> for StatusCode
sourceimpl PartialOrd<StatusCode> for StatusCode
impl PartialOrd<StatusCode> for StatusCode
sourcefn partial_cmp(&self, other: &StatusCode) -> Option<Ordering>
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 · sourcefn lt(&self, other: &Rhs) -> bool
fn lt(&self, other: &Rhs) -> bool
This method tests less than (for self
and other
) and is used by the <
operator. Read more
1.0.0 · sourcefn 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
sourceimpl<'a> TryFrom<&'a [u8]> for StatusCode
impl<'a> TryFrom<&'a [u8]> for StatusCode
sourceimpl<'a> TryFrom<&'a str> for StatusCode
impl<'a> TryFrom<&'a str> for StatusCode
sourceimpl TryFrom<u16> for StatusCode
impl TryFrom<u16> for StatusCode
impl Copy for StatusCode
impl Eq for StatusCode
impl StructuralEq for StatusCode
impl StructuralPartialEq for StatusCode
Auto Trait Implementations
impl RefUnwindSafe for StatusCode
impl Send for StatusCode
impl Sync for StatusCode
impl Unpin for StatusCode
impl UnwindSafe for StatusCode
Blanket Implementations
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more