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
impl StunMessageBuilder
sourcepub fn new(method: MessageMethod, class: MessageClass) -> StunMessageBuilder
pub fn new(method: MessageMethod, class: MessageClass) -> StunMessageBuilder
sourcepub fn with_transaction_id(self, transaction_id: TransactionId) -> Self
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
sourcepub fn with_attribute<T>(self, attribute: T) -> Selfwhere
T: Into<StunAttribute>,
pub fn with_attribute<T>(self, attribute: T) -> Selfwhere
T: Into<StunAttribute>,
Adds an attribute to the message.
sourcepub fn build(self) -> StunMessage
pub fn build(self) -> StunMessage
Creates the STUN message.
Trait Implementations§
Auto Trait Implementations§
impl Freeze for StunMessageBuilder
impl RefUnwindSafe for StunMessageBuilder
impl !Send for StunMessageBuilder
impl !Sync for StunMessageBuilder
impl Unpin for StunMessageBuilder
impl UnwindSafe for StunMessageBuilder
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