1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
use rsip_derives::UntypedHeader;

/// The `Max-Forwards` header in its [untyped](super) form.
#[derive(UntypedHeader, Debug, PartialEq, Eq, Clone)]
pub struct MaxForwards(String);

impl Default for MaxForwards {
    fn default() -> Self {
        Self("0".into())
    }
}

impl MaxForwards {
    pub fn num(&self) -> Result<u32, crate::Error> {
        use crate::headers::untyped::UntypedHeader;

        Ok(self.value().parse::<u32>()?)
    }
}

impl From<u32> for MaxForwards {
    fn from(from: u32) -> Self {
        Self(from.to_string())
    }
}