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(PartialEq, Eq, Debug, Copy, Clone)]
9pub enum TcpType {
10    /// The default value. For example UDP candidates do not need this field.
11    Unspecified,
12    /// Active TCP candidate, which initiates TCP connections.
13    Active,
14    /// Passive TCP candidate, only accepts TCP connections.
15    Passive,
16    /// Like `Active` and `Passive` at the same time.
17    SimultaneousOpen,
18}
19
20// from creates a new TCPType from string.
21impl From<&str> for TcpType {
22    fn from(raw: &str) -> Self {
23        match raw {
24            "active" => Self::Active,
25            "passive" => Self::Passive,
26            "so" => Self::SimultaneousOpen,
27            _ => Self::Unspecified,
28        }
29    }
30}
31
32impl fmt::Display for TcpType {
33    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
34        let s = match *self {
35            Self::Active => "active",
36            Self::Passive => "passive",
37            Self::SimultaneousOpen => "so",
38            Self::Unspecified => "unspecified",
39        };
40        write!(f, "{s}")
41    }
42}
43
44impl Default for TcpType {
45    fn default() -> Self {
46        Self::Unspecified
47    }
48}