summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorDavid Lönnhager <david.l@mullvad.net>2020-08-14 16:26:35 +0200
committerDavid Lönnhager <david.l@mullvad.net>2020-08-20 14:41:41 +0200
commit81ac142ca8ad986cf503d3cae62e73c058fbbe39 (patch)
tree30925bac9d90299e6ced6d4698f7f0b625183807
parent45ee23da9eda49462db6cc55f0e4f78b133727b9 (diff)
downloadmullvadvpn-81ac142ca8ad986cf503d3cae62e73c058fbbe39.tar.xz
mullvadvpn-81ac142ca8ad986cf503d3cae62e73c058fbbe39.zip
Update Constraint type
-rw-r--r--mullvad-types/src/relay_constraints.rs16
1 files changed, 16 insertions, 0 deletions
diff --git a/mullvad-types/src/relay_constraints.rs b/mullvad-types/src/relay_constraints.rs
index 6eba0fbd95..c5d58f621f 100644
--- a/mullvad-types/src/relay_constraints.rs
+++ b/mullvad-types/src/relay_constraints.rs
@@ -72,6 +72,13 @@ impl<T: fmt::Debug + Clone + Eq + PartialEq> Constraint<T> {
Constraint::Only(ref value) => Constraint::Only(value),
}
}
+
+ pub fn option(self) -> Option<T> {
+ match self {
+ Constraint::Any => None,
+ Constraint::Only(value) => Some(value),
+ }
+ }
}
impl<T: fmt::Debug + Clone + Eq + PartialEq> Default for Constraint<T> {
@@ -91,6 +98,15 @@ impl<T: fmt::Debug + Clone + Eq + PartialEq> Match<T> for Constraint<T> {
}
}
+impl<T: fmt::Debug + Clone + Eq + PartialEq> From<Option<T>> for Constraint<T> {
+ fn from(value: Option<T>) -> Self {
+ match value {
+ Some(value) => Constraint::Only(value),
+ None => Constraint::Any,
+ }
+ }
+}
+
/// Specifies a specific endpoint or [`RelayConstraints`] to use when `mullvad-daemon` selects a
/// relay.
#[derive(Debug, Clone, Eq, PartialEq, Deserialize, Serialize)]