pub struct StunMessageBuilder(_);
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

Creates a new builder.

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

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

Adds an attribute to the message.

Creates the STUN message.

Trait Implementations

Formats the value using the given formatter. Read more

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more
Immutably borrows from an owned value. Read more
Mutably borrows from an owned value. Read more

Returns the argument unchanged.

Calls U::from(self).

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

The type returned in the event of a conversion error.
Performs the conversion.
The type returned in the event of a conversion error.
Performs the conversion.