rtc_ice/tcp_type/
mod.rs

1#[cfg(test)]
2mod tcp_type_test;
3
4use std::fmt;
5
6// TCPType is the type of ICE TCP candidate as described in
7// ttps://tools.ietf.org/html/rfc6544#section-4.5
8#[derive(Default, PartialEq, Eq, Debug, Copy, Clone)]
9pub enum TcpType {
10    /// The default value. For example UDP candidates do not need this field.
11    #[default]
12    Unspecified,
13    /// Active TCP candidate, which initiates TCP connections.
14    Active,
15    /// Passive TCP candidate, only accepts TCP connections.
16    Passive,
17    /// Like `Active` and `Passive` at the same time.
18    SimultaneousOpen,
19}
20
21// from creates a new TCPType from string.
22impl From<&str> for TcpType {
23    fn from(raw: &str) -> Self {
24        match raw {
25            "active" => Self::Active,
26            "passive" => Self::Passive,
27            "so" => Self::SimultaneousOpen,
28            _ => Self::Unspecified,
29        }
30    }
31}
32
33impl fmt::Display for TcpType {
34    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
35        let s = match *self {
36            Self::Active => "active",
37            Self::Passive => "passive",
38            Self::SimultaneousOpen => "so",
39            Self::Unspecified => "unspecified",
40        };
41        write!(f, "{s}")
42    }
43}