allow instantiating PortForwardProtocol from a string

This commit is contained in:
lemonsh
2023-05-20 11:28:59 +02:00
parent 470d5f5814
commit 7d5a93e30d
2 changed files with 11 additions and 0 deletions

View File

@ -279,6 +279,7 @@ impl ConnectBox {
} }
/// Specifies the action to perform with a given port forward. Used in conjunction with [`ConnectBox::edit_port_forwards`] /// Specifies the action to perform with a given port forward. Used in conjunction with [`ConnectBox::edit_port_forwards`]
#[derive(Debug, Clone, Copy)]
pub enum PortForwardAction { pub enum PortForwardAction {
/// Don't do anything with the port forward /// Don't do anything with the port forward
Keep, Keep,

View File

@ -78,6 +78,16 @@ impl PortForwardProtocol {
PortForwardProtocol::Both => "3", PortForwardProtocol::Both => "3",
} }
} }
#[must_use]
pub fn new(s: &str) -> Option<Self> {
match s.to_lowercase().as_str() {
"tcp" => Some(Self::Tcp),
"udp" => Some(Self::Udp),
"both" => Some(Self::Both),
_ => None,
}
}
} }
impl<'de> Deserialize<'de> for PortForwardProtocol { impl<'de> Deserialize<'de> for PortForwardProtocol {