Skip to content

Commit

Permalink
Move Protocol trait impls to io/mod.rs
Browse files Browse the repository at this point in the history
  • Loading branch information
algesten committed Oct 18, 2023
1 parent 3e819de commit 5f04aa6
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 33 deletions.
33 changes: 0 additions & 33 deletions src/ice/candidate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -446,39 +446,6 @@ impl fmt::Display for CandidateKind {
}
}

impl TryFrom<&str> for Protocol {
type Error = ();

fn try_from(proto: &str) -> Result<Self, Self::Error> {
let proto = proto.to_lowercase();
match proto.as_str() {
"udp" => Ok(Protocol::Udp),
"tcp" => Ok(Protocol::Tcp),
"ssltcp" => Ok(Protocol::SslTcp),
"tls" => Ok(Protocol::Tls),
_ => Err(()),
}
}
}

impl From<Protocol> for &str {
fn from(proto: Protocol) -> Self {
match proto {
Protocol::Udp => "udp",
Protocol::Tcp => "tcp",
Protocol::SslTcp => "ssltcp",
Protocol::Tls => "tls",
}
}
}

impl fmt::Display for Protocol {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
let x: &str = (*self).into();
write!(f, "{}", x)
}
}

fn is_valid_ip(ip: IpAddr) -> bool {
match ip {
IpAddr::V4(v) => {
Expand Down
33 changes: 33 additions & 0 deletions src/io/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -243,3 +243,36 @@ impl fmt::Debug for DatagramRecv<'_> {
}
//
}

impl TryFrom<&str> for Protocol {
type Error = ();

fn try_from(proto: &str) -> Result<Self, Self::Error> {
let proto = proto.to_lowercase();
match proto.as_str() {
"udp" => Ok(Protocol::Udp),
"tcp" => Ok(Protocol::Tcp),
"ssltcp" => Ok(Protocol::SslTcp),
"tls" => Ok(Protocol::Tls),
_ => Err(()),
}
}
}

impl From<Protocol> for &str {
fn from(proto: Protocol) -> Self {
match proto {
Protocol::Udp => "udp",
Protocol::Tcp => "tcp",
Protocol::SslTcp => "ssltcp",
Protocol::Tls => "tls",
}
}
}

impl fmt::Display for Protocol {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
let x: &str = (*self).into();
write!(f, "{}", x)
}
}

0 comments on commit 5f04aa6

Please sign in to comment.