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