summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
-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)]