pub struct ErrorCode { /* private fields */ }Expand description
The ErrorCode contains a numeric error code value in the range of 300
to 699 plus a textual reason phrase encoded in UTF-8
RFC3629; it is also
consistent in its code assignments and semantics with SIP
RFC3261
and HTTP RFC7231.
The reason phrase is meant for diagnostic purposes and can be anything
appropriate for the error code.
Recommended reason phrases for the defined error codes are included
in the IANA registry for error codes. The reason phrase MUST be a
UTF-8-encoded RFC3629
sequence of fewer than 128 characters (which can be as long as 509 bytes
when encoding them or 763 bytes when decoding them).
Examples
let attr = ErrorCode::new(420, "Unknown Attribute")?;
assert_eq!(attr.class(), 4);
assert_eq!(attr.number(), 20);
assert_eq!(attr.error_code(), 420);
assert_eq!(attr.reason(), "Unknown Attribute");Implementations
sourceimpl ErrorCode
impl ErrorCode
sourcepub fn new(error_code: u16, reason: &str) -> Result<Self, StunError>
pub fn new(error_code: u16, reason: &str) -> Result<Self, StunError>
Creates a new ErrorCode type.
Arguments:
error_code- The numeric error code.reason- The reason phrase.
Return:
The ErrorCode type or a StunError if the numeric
error value is not in the range of 300 to 699.
sourcepub fn error_code(&self) -> u16
pub fn error_code(&self) -> u16
Returns the numeric error code value .