xref: /webrtc/ice/src/tcp_type/mod.rs (revision 5d8fe953)
1 #[cfg(test)]
2 mod tcp_type_test;
3 
4 use 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)]
9 pub 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.
21 impl From<&str> for TcpType {
from(raw: &str) -> Self22     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 
32 impl fmt::Display for TcpType {
fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result33     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 
44 impl Default for TcpType {
default() -> Self45     fn default() -> Self {
46         Self::Unspecified
47     }
48 }
49