sip_codec/headers/
max_forwards.rs

1use std::fmt::{Display, Error, Formatter};
2
3use http::header::HeaderValue;
4
5use crate::headers::ParseHeader;
6
7#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
8pub struct MaxForwards(pub u32);
9
10impl ParseHeader for MaxForwards {
11	fn header_name() -> &'static [&'static str] {
12		&["max-forwards"]
13	}
14
15	fn decode<'a>(headers: impl IntoIterator<Item = &'a HeaderValue>) -> Option<Self> {
16		headers
17			.into_iter()
18			.next()
19			.and_then(|header| header.to_str().ok())
20			.and_then(|value| value.parse().ok())
21			.map(Self)
22	}
23}
24
25impl Into<u32> for MaxForwards {
26	fn into(self) -> u32 {
27		self.0
28	}
29}
30
31impl Display for MaxForwards {
32	fn fmt(&self, f: &mut Formatter) -> Result<(), Error> {
33		write!(f, "{}", self.0)
34	}
35}