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