Struct stun_types::message::MessageType
source · pub struct MessageType(/* private fields */);Expand description
The type of a Message. A combination of a MessageClass and a STUN method.
Implementations§
source§impl MessageType
impl MessageType
sourcepub fn from_class_method(class: MessageClass, method: u16) -> Self
pub fn from_class_method(class: MessageClass, method: u16) -> Self
Create a new MessageType from the provided MessageClass and method
§Examples
let mtype = MessageType::from_class_method(MessageClass::Indication, BINDING);
assert_eq!(mtype.has_class(MessageClass::Indication), true);
assert_eq!(mtype.has_method(BINDING), true);sourcepub fn class(self) -> MessageClass
pub fn class(self) -> MessageClass
Retrieves the class of a MessageType
§Examples
let mtype = MessageType::from_class_method(MessageClass::Indication, BINDING);
assert_eq!(mtype.class(), MessageClass::Indication);sourcepub fn has_class(self, cls: MessageClass) -> bool
pub fn has_class(self, cls: MessageClass) -> bool
Returns whether class of a MessageType is equal to the provided MessageClass
§Examples
let mtype = MessageType::from_class_method(MessageClass::Indication, BINDING);
assert!(mtype.has_class(MessageClass::Indication));sourcepub fn is_response(self) -> bool
pub fn is_response(self) -> bool
Returns whether the class of a MessageType indicates a response Message
§Examples
assert_eq!(MessageType::from_class_method(MessageClass::Indication, BINDING)
.is_response(), false);
assert_eq!(MessageType::from_class_method(MessageClass::Request, BINDING)
.is_response(), false);
assert_eq!(MessageType::from_class_method(MessageClass::Success, BINDING)
.is_response(), true);
assert_eq!(MessageType::from_class_method(MessageClass::Error, BINDING)
.is_response(), true);sourcepub fn method(self) -> u16
pub fn method(self) -> u16
Returns the method of a MessageType
§Examples
let mtype = MessageType::from_class_method(MessageClass::Indication, BINDING);
assert_eq!(mtype.method(), BINDING);sourcepub fn has_method(self, method: u16) -> bool
pub fn has_method(self, method: u16) -> bool
Returns whether the method of a MessageType is equal to the provided value
§Examples
let mtype = MessageType::from_class_method(MessageClass::Indication, BINDING);
assert_eq!(mtype.has_method(BINDING), true);sourcepub fn to_bytes(self) -> Vec<u8>
pub fn to_bytes(self) -> Vec<u8>
Convert a MessageType to network bytes
sourcepub fn from_bytes(data: &[u8]) -> Result<Self, StunParseError>
pub fn from_bytes(data: &[u8]) -> Result<Self, StunParseError>
Convert a set of network bytes into a MessageType or return an error
Trait Implementations§
source§impl Clone for MessageType
impl Clone for MessageType
source§fn clone(&self) -> MessageType
fn clone(&self) -> MessageType
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 MessageType
impl Debug for MessageType
source§impl Display for MessageType
impl Display for MessageType
source§impl PartialEq for MessageType
impl PartialEq for MessageType
source§fn eq(&self, other: &MessageType) -> bool
fn eq(&self, other: &MessageType) -> bool
This method tests for
self and other values to be equal, and is used
by ==.source§impl TryFrom<&[u8]> for MessageType
impl TryFrom<&[u8]> for MessageType
impl Copy for MessageType
impl Eq for MessageType
impl StructuralPartialEq for MessageType
Auto Trait Implementations§
impl Freeze for MessageType
impl RefUnwindSafe for MessageType
impl Send for MessageType
impl Sync for MessageType
impl Unpin for MessageType
impl UnwindSafe for MessageType
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§default unsafe fn clone_to_uninit(&self, dst: *mut T)
default unsafe fn clone_to_uninit(&self, dst: *mut T)
🔬This is a nightly-only experimental API. (
clone_to_uninit)source§impl<T> CloneToUninit for Twhere
T: Copy,
impl<T> CloneToUninit for Twhere
T: Copy,
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)