ftth_rsip/headers/untyped/
contact.rs

1use crate::{
2    common::{
3        uri::{param, Param},
4        Uri,
5    },
6    headers::untyped::ToTypedHeader,
7    Error,
8};
9use rsip_derives::{ToTypedHeader, UntypedHeader};
10
11/// The `Contact` header in its [untyped](super) form.
12#[derive(ToTypedHeader, UntypedHeader, Debug, PartialEq, Eq, Clone)]
13pub struct Contact(String);
14
15impl Contact {
16    pub fn display_name(&self) -> Result<Option<String>, Error> {
17        self.typed().map(|s| s.display_name)
18    }
19
20    pub fn uri(&self) -> Result<Uri, Error> {
21        Ok(self.typed()?.uri)
22    }
23
24    pub fn params(&self) -> Result<Vec<Param>, Error> {
25        Ok(self.typed()?.params)
26    }
27
28    pub fn expires(&self) -> Result<Option<param::Expires>, Error> {
29        self.typed().map(|s| s.expires().cloned())
30    }
31
32    pub fn with_uri(mut self, uri: Uri) -> Result<Self, Error> {
33        let mut typed = self.typed()?;
34        typed.uri = uri;
35        self.0 = typed.into();
36        Ok(self)
37    }
38
39    //TODO: this should be replace_uri not mut uri
40    pub fn mut_uri(&mut self, uri: Uri) -> Result<&mut Self, Error> {
41        let mut typed = self.typed()?;
42        typed.uri = uri;
43        self.0 = typed.into();
44        Ok(self)
45    }
46
47    pub fn with_params(mut self, params: Vec<Param>) -> Result<Self, Error> {
48        let mut typed = self.typed()?;
49        typed.params = params;
50        self.0 = typed.into();
51        Ok(self)
52    }
53
54    pub fn mut_params(&mut self, params: Vec<Param>) -> Result<&mut Self, Error> {
55        let mut typed = self.typed()?;
56        typed.params = params;
57        self.0 = typed.into();
58        Ok(self)
59    }
60}