ftth_rsip/headers/untyped/
from.rs1use crate::{
2 common::uri::{param::Tag, Param, Uri},
3 headers::untyped::ToTypedHeader,
4 Error,
5};
6use rsip_derives::{ToTypedHeader, UntypedHeader};
7
8#[derive(UntypedHeader, ToTypedHeader, Debug, PartialEq, Eq, Clone)]
10pub struct From(String);
11
12impl From {
13 pub fn display_name(&self) -> Result<Option<String>, Error> {
14 self.typed().map(|s| s.display_name)
15 }
16
17 pub fn uri(&self) -> Result<Uri, Error> {
18 self.typed().map(|s| s.uri)
19 }
20
21 pub fn params(&self) -> Result<Vec<Param>, Error> {
22 self.typed().map(|s| s.params)
23 }
24
25 pub fn tag(&self) -> Result<Option<Tag>, Error> {
26 self.typed().map(|s| s.tag().cloned())
27 }
28
29 pub fn with_tag(mut self, tag: Tag) -> Result<Self, Error> {
30 self.0 = self.typed()?.with_tag(tag).into();
31 Ok(self)
32 }
33
34 pub fn mut_tag(&mut self, tag: Tag) -> Result<&mut Self, Error> {
35 self.0 = self.typed()?.with_tag(tag).into();
36 Ok(self)
37 }
38
39 pub fn with_uri(mut self, uri: Uri) -> Result<Self, Error> {
40 self.0 = self.typed()?.with_uri(uri).into();
41 Ok(self)
42 }
43
44 pub fn mut_uri(&mut self, uri: Uri) -> Result<&mut Self, Error> {
45 self.0 = self.typed()?.with_uri(uri).into();
46 Ok(self)
47 }
48}