stun_rs

Struct MessageMethod

source
pub struct MessageMethod(/* private fields */);
Expand description

The STUN method is a 12 bits hex number in the range 0x000-0xFFF but valid values are defined in the range 0x00-0xFF. STUN methods in the range 0x000-0x07F are assigned by IETF Review RFC8126. STUN methods in the range 0x080-0x0FF are assigned by Expert Review.

§Examples

 // Create a binding method
 let binding = MessageMethod::try_from(0x001)?;
 assert_eq!(binding.as_u16(), 0x001);
 // Binding request is within the range of valid values 0x00-0xFF
 assert!(binding.is_valid());

 // Create a custom method
 let method = MessageMethod::try_from(0x100)?;
 // This method is out of the range of valid values 0x00-0xFF
 assert!(!method.is_valid());

 // Creating a message method out of 12 bits range 0x000-0xFFF
 // will result in an error
 assert_eq!(MessageMethod::try_from(0x1000).expect_err("Error expected"), StunErrorType::InvalidParam);

Implementations§

source§

impl MessageMethod

source

pub fn as_u16(&self) -> u16

Returns the u16 representation of this message method.

source

pub fn is_valid(&self) -> bool

Returns true if the method is within the valid range 0x00-0xFF

Trait Implementations§

source§

impl Clone for MessageMethod

source§

fn clone(&self) -> MessageMethod

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
source§

impl Debug for MessageMethod

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl Default for MessageMethod

source§

fn default() -> MessageMethod

Returns the “default value” for a type. Read more
source§

impl PartialEq for MessageMethod

source§

fn eq(&self, other: &MessageMethod) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl TryFrom<u16> for MessageMethod

source§

type Error = StunError

The type returned in the event of a conversion error.
source§

fn try_from(value: u16) -> Result<Self, Self::Error>

Performs the conversion.
source§

impl Copy for MessageMethod

source§

impl Eq for MessageMethod

source§

impl StructuralPartialEq for MessageMethod

Auto Trait Implementations§

Blanket Implementations§

source§

impl<T> Any for T
where T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for T
where T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> CloneToUninit for T
where T: Clone,

source§

unsafe fn clone_to_uninit(&self, dst: *mut T)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dst. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for T
where U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T> Same for T

source§

type Output = T

Should always be Self
source§

impl<T> ToOwned for T
where T: Clone,

source§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

source§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

source§

fn vzip(self) -> V