diff options
author | metamuffin <metamuffin@disroot.org> | 2024-07-03 23:49:00 +0200 |
---|---|---|
committer | metamuffin <metamuffin@disroot.org> | 2024-07-03 23:49:00 +0200 |
commit | 2c1977bbf97653bc3faae9d4cebcfb61c6cd347b (patch) | |
tree | 1e429bea320023b19b1043b204eb5783293190a5 /src/headers.rs | |
download | sip-rs-2c1977bbf97653bc3faae9d4cebcfb61c6cd347b.tar sip-rs-2c1977bbf97653bc3faae9d4cebcfb61c6cd347b.tar.bz2 sip-rs-2c1977bbf97653bc3faae9d4cebcfb61c6cd347b.tar.zst |
stuff
Diffstat (limited to 'src/headers.rs')
-rw-r--r-- | src/headers.rs | 36 |
1 files changed, 36 insertions, 0 deletions
diff --git a/src/headers.rs b/src/headers.rs new file mode 100644 index 0000000..d837ee5 --- /dev/null +++ b/src/headers.rs @@ -0,0 +1,36 @@ +use std::{fmt::Display, str::FromStr}; + +macro_rules! header { + ($hname:literal, struct $name:ident($type:ty)) => { + pub struct $name(pub $type); + impl Header for $name { + const NAME: &'static str = $hname; + } + impl Display for $name { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + write!(f, "{}", self.0) + } + } + impl FromStr for $name { + type Err = anyhow::Error; + fn from_str(s: &str) -> Result<Self, Self::Err> { + Ok($name(<$type>::from_str(s)?)) + } + } + }; +} + +pub trait Header: FromStr<Err = anyhow::Error> + Display { + const NAME: &'static str; +} + +header!("Content-Length", struct ContentLength(usize)); +header!("Call-ID", struct CallID(String)); +header!("CSeq", struct CSeq(String)); +header!("Via", struct Via(String)); +header!("Contact", struct Contact(String)); +header!("Max-Forwards", struct MaxForwards(usize)); +header!("From", struct From(String)); +header!("To", struct To(String)); +header!("User-Agent", struct UserAgent(String)); +header!("Allow", struct Allow(String)); |