ftth_rsip/headers/typed/
allow.rs1use crate::{common::Method, Error};
2use rsip_derives::TypedHeader;
3use std::convert::TryFrom;
4
5#[doc(hidden)]
6pub use super::tokenizers::TokenListTokenizer as Tokenizer;
7
8#[derive(TypedHeader, Eq, PartialEq, Clone, Debug)]
10pub struct Allow(pub Vec<Method>);
11
12impl From<Vec<Method>> for Allow {
13 fn from(methods: Vec<Method>) -> Self {
14 Self(methods)
15 }
16}
17
18impl<'a> TryFrom<Tokenizer<'a>> for Allow {
19 type Error = Error;
20
21 fn try_from(tokenizer: Tokenizer) -> Result<Self, Self::Error> {
22 use std::str::FromStr;
23
24 let methods = tokenizer
25 .tokens
26 .into_iter()
27 .map(Method::from_str)
28 .collect::<Result<Vec<Method>, Error>>()?;
29 Ok(Self(methods))
30 }
31}
32
33impl std::fmt::Display for Allow {
34 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
35 write!(
36 f,
37 "{}",
38 self.0
39 .iter()
40 .map(|m| m.to_string())
41 .collect::<Vec<String>>()
42 .join(", ")
43 )
44 }
45}