From 7d5a93e30d265c577b5ec773dd1b22bbdf2b9e3e Mon Sep 17 00:00:00 2001 From: lemonsh Date: Sat, 20 May 2023 11:28:59 +0200 Subject: [PATCH] allow instantiating PortForwardProtocol from a string --- connectbox/src/lib.rs | 1 + connectbox/src/models.rs | 10 ++++++++++ 2 files changed, 11 insertions(+) diff --git a/connectbox/src/lib.rs b/connectbox/src/lib.rs index 99eb6b1..15c482a 100644 --- a/connectbox/src/lib.rs +++ b/connectbox/src/lib.rs @@ -279,6 +279,7 @@ impl ConnectBox { } /// 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 { /// Don't do anything with the port forward Keep, diff --git a/connectbox/src/models.rs b/connectbox/src/models.rs index a64d8a7..29a4a9b 100644 --- a/connectbox/src/models.rs +++ b/connectbox/src/models.rs @@ -78,6 +78,16 @@ impl PortForwardProtocol { PortForwardProtocol::Both => "3", } } + + #[must_use] + pub fn new(s: &str) -> Option { + 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 {