sdp_rs/lines/common/
nettype.rs

1/// The Nettype as it appears in the connection or origin lines. It's not a `Copy` type since it
2/// supports abstract types, not even defined in any RFC.
3#[derive(Debug, PartialEq, Eq, Ord, PartialOrd, Clone)]
4pub enum Nettype {
5    In,
6    Other(String),
7}
8
9impl<'a> From<&'a str> for Nettype {
10    fn from(s: &str) -> Self {
11        if s.eq("IN") {
12            Self::In
13        } else {
14            Self::Other(s.into())
15        }
16    }
17}
18
19impl std::fmt::Display for Nettype {
20    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
21        match self {
22            Self::In => write!(f, "IN",),
23            Self::Other(other) => write!(f, "{}", other),
24        }
25    }
26}
27
28#[cfg(test)]
29mod tests {
30    use super::*;
31
32    #[test]
33    fn from_str1() {
34        let part = "IN";
35
36        assert_eq!(Nettype::from(part), Nettype::In);
37    }
38
39    #[test]
40    fn from_str2() {
41        let part = "in";
42
43        assert_eq!(Nettype::from(part), Nettype::Other("in".into()));
44    }
45
46    #[test]
47    fn display1() {
48        assert_eq!(Nettype::In.to_string(), "IN");
49    }
50}