ftth_rsip/headers/untyped/
cseq.rs

1use crate::{common::Method, headers::untyped::ToTypedHeader, Error};
2use rsip_derives::{ToTypedHeader, UntypedHeader};
3
4/// The `CSeq` header in its [untyped](super) form.
5#[derive(UntypedHeader, ToTypedHeader, Debug, PartialEq, Eq, Clone)]
6#[header(display_name = "CSeq")]
7pub struct CSeq(String);
8
9impl CSeq {
10    pub fn seq(&self) -> Result<u32, Error> {
11        self.typed().map(|s| s.seq)
12    }
13
14    pub fn mut_seq(&mut self, new_seq: u32) -> Result<&mut Self, Error> {
15        let mut typed = self.typed()?;
16        typed.seq = new_seq;
17        self.0 = typed.into();
18        Ok(self)
19    }
20
21    pub fn method(&self) -> Result<Method, Error> {
22        self.typed().map(|s| s.method)
23    }
24
25    pub fn mut_method(&mut self, new_method: Method) -> Result<&mut Self, Error> {
26        let mut typed = self.typed()?;
27        typed.method = new_method;
28        self.0 = typed.into();
29        Ok(self)
30    }
31}