diff options
Diffstat (limited to 'talpid-core/src')
| -rw-r--r-- | talpid-core/src/net.rs | 13 |
1 files changed, 13 insertions, 0 deletions
diff --git a/talpid-core/src/net.rs b/talpid-core/src/net.rs index ba8a3fe665..9a75859d61 100644 --- a/talpid-core/src/net.rs +++ b/talpid-core/src/net.rs @@ -1,4 +1,5 @@ use std::net::{IpAddr, SocketAddr}; +use std::str::FromStr; /// Represents a network layer IP address together with the transport layer protocol and port. #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] @@ -27,3 +28,15 @@ pub enum TransportProtocol { /// Represents the TCP transport protocol. Tcp, } + +impl FromStr for TransportProtocol { + type Err = (); + + fn from_str(s: &str) -> ::std::result::Result<TransportProtocol, Self::Err> { + match s { + "udp" => Ok(TransportProtocol::Udp), + "tcp" => Ok(TransportProtocol::Tcp), + _ => Err(()), + } + } +} |
