Struct async_nats::status::StatusCode
source · 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
source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
source§unsafe fn clone_to_uninit(&self, dst: *mut T)
unsafe fn clone_to_uninit(&self, dst: *mut T)
🔬This is a nightly-only experimental API. (
clone_to_uninit
)