stun_rs/attributes/turn/
lifetime.rs

1const LIFETIME: u16 = 0x000D;
2
3crate::common::integer_attribute!(
4    /// The `LifeTime` attribute represents the duration for which the server
5    /// will maintain an allocation in the absence of a refresh.  The TURN
6    /// client can include the LIFETIME attribute with the desired lifetime
7    /// in Allocate and Refresh requests.  The value portion of this
8    /// attribute is 4 bytes long and consists of a 32-bit unsigned integral
9    /// value representing the number of seconds remaining until expiration.
10    ///
11    /// # Examples
12    ///```rust
13    /// # use stun_rs::attributes::turn::LifeTime;
14    /// let attr = LifeTime::from(1234);
15    /// assert_eq!(attr, 1234);
16    ///```
17    LifeTime,
18    LIFETIME,
19    u32,
20);
21
22#[cfg(test)]
23mod tests {
24    use super::*;
25    use crate::StunAttribute;
26
27    #[test]
28    fn lifetime_stunt_attribute() {
29        let attr = StunAttribute::LifeTime(LifeTime::from(1234));
30        assert!(attr.is_life_time());
31        assert!(attr.as_life_time().is_ok());
32        assert!(attr.as_unknown().is_err());
33
34        assert!(attr.attribute_type().is_comprehension_required());
35        assert!(!attr.attribute_type().is_comprehension_optional());
36
37        let dbg_fmt = format!("{:?}", attr);
38        assert_eq!("LifeTime(LifeTime(1234))", dbg_fmt);
39    }
40}