stun_rs

Struct StunMessageBuilder

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

The StunMessageBuilder ease the creation of a StunMessage

§Examples

 // Create a SUN request message with a random transaction ID.
 let message = StunMessageBuilder::new(
     BINDING,
     MessageClass::Request,
 )
 .with_attribute(UserName::try_from("test-username")?)
 .with_attribute(Software::new("test-software")?)
 .build();

 let username = message.get::<UserName>()
   .ok_or("UserName attriute not found")?
   .as_user_name()?;
 assert_eq!(username, "test-username");

 let software = message.get::<Software>()
   .ok_or("Software attriute not found")?
   .as_software()?;
 assert_eq!(software, "test-software");

 // Nonce attribute must return None
 assert!(message.get::<Nonce>().is_none());

Implementations§

source§

impl StunMessageBuilder

source

pub fn new(method: MessageMethod, class: MessageClass) -> StunMessageBuilder

Creates a new builder.

§Arguments:
  • method - Message method.
  • class - Message class.
source

pub fn with_transaction_id(self, transaction_id: TransactionId) -> Self

Creates a STUN message using an specific transaction ID. If no TransactionId is specified, a random one will be used

source

pub fn with_attribute<T>(self, attribute: T) -> Self
where T: Into<StunAttribute>,

Adds an attribute to the message.

source

pub fn build(self) -> StunMessage

Creates the STUN message.

Trait Implementations§

source§

impl Debug for StunMessageBuilder

source§

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

Formats the value using the given formatter. Read more

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> 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, 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