diff options
| author | David Lönnhager <david.l@mullvad.net> | 2023-04-17 10:07:59 +0200 |
|---|---|---|
| committer | David Lönnhager <david.l@mullvad.net> | 2023-04-17 10:08:13 +0200 |
| commit | 5dff789072b7a18c5d5a73d1dd7abac51a15cc7a (patch) | |
| tree | 664303f0e19fa58d4af2e7c0718e9607492c89a5 | |
| parent | c3dd7239b7032ae4e62446c86ae0a4154a869629 (diff) | |
| download | mullvadvpn-5dff789072b7a18c5d5a73d1dd7abac51a15cc7a.tar.xz mullvadvpn-5dff789072b7a18c5d5a73d1dd7abac51a15cc7a.zip | |
Simplify Constraint bounds
| -rw-r--r-- | mullvad-types/src/relay_constraints.rs | 27 |
1 files changed, 12 insertions, 15 deletions
diff --git a/mullvad-types/src/relay_constraints.rs b/mullvad-types/src/relay_constraints.rs index 0a6f742246..79a95ff031 100644 --- a/mullvad-types/src/relay_constraints.rs +++ b/mullvad-types/src/relay_constraints.rs @@ -26,12 +26,12 @@ pub trait Set<T> { #[cfg_attr(target_os = "android", derive(FromJava, IntoJava))] #[cfg_attr(target_os = "android", jnix(package = "net.mullvad.mullvadvpn.model"))] #[cfg_attr(target_os = "android", jnix(bounds = "T: android.os.Parcelable"))] -pub enum Constraint<T: fmt::Debug + Clone + Eq + PartialEq> { +pub enum Constraint<T> { Any, Only(T), } -impl<T: fmt::Debug + fmt::Display + Clone + Eq> fmt::Display for Constraint<T> { +impl<T: fmt::Display> fmt::Display for Constraint<T> { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> Result<(), fmt::Error> { match self { Constraint::Any => "any".fmt(f), @@ -40,7 +40,7 @@ impl<T: fmt::Debug + fmt::Display + Clone + Eq> fmt::Display for Constraint<T> { } } -impl<T: fmt::Debug + Clone + Eq + PartialEq> Constraint<T> { +impl<T> Constraint<T> { pub fn unwrap(self) -> T { match self { Constraint::Any => panic!("called `Constraint::unwrap()` on an `Any` value"), @@ -62,10 +62,7 @@ impl<T: fmt::Debug + Clone + Eq + PartialEq> Constraint<T> { } } - pub fn map<U: fmt::Debug + Clone + Eq + PartialEq, F: FnOnce(T) -> U>( - self, - f: F, - ) -> Constraint<U> { + pub fn map<U, F: FnOnce(T) -> U>(self, f: F) -> Constraint<U> { match self { Constraint::Any => Constraint::Any, Constraint::Only(value) => Constraint::Only(f(value)), @@ -96,7 +93,9 @@ impl<T: fmt::Debug + Clone + Eq + PartialEq> Constraint<T> { Constraint::Only(value) => Some(value), } } +} +impl<T: PartialEq> Constraint<T> { pub fn matches_eq(&self, other: &T) -> bool { match self { Constraint::Any => true, @@ -107,15 +106,15 @@ impl<T: fmt::Debug + Clone + Eq + PartialEq> Constraint<T> { // Using the default attribute fails on Android #[allow(clippy::derivable_impls)] -impl<T: fmt::Debug + Clone + Eq + PartialEq> Default for Constraint<T> { +impl<T> Default for Constraint<T> { fn default() -> Self { Constraint::Any } } -impl<T: Copy + fmt::Debug + Clone + Eq + PartialEq> Copy for Constraint<T> {} +impl<T: Copy> Copy for Constraint<T> {} -impl<T: fmt::Debug + Clone + Eq + Match<U>, U> Match<U> for Constraint<T> { +impl<T: Match<U>, U> Match<U> for Constraint<T> { fn matches(&self, other: &U) -> bool { match *self { Constraint::Any => true, @@ -124,12 +123,10 @@ impl<T: fmt::Debug + Clone + Eq + Match<U>, U> Match<U> for Constraint<T> { } } -impl<T: fmt::Debug + Clone + Eq + Set<U>, U: fmt::Debug + Clone + Eq> Set<Constraint<U>> - for Constraint<T> -{ +impl<T: Set<U>, U> Set<Constraint<U>> for Constraint<T> { fn is_subset(&self, other: &Constraint<U>) -> bool { match self { - Constraint::Any => *other == Constraint::Any, + Constraint::Any => other.is_any(), Constraint::Only(ref constraint) => match other { Constraint::Only(ref other_constraint) => constraint.is_subset(other_constraint), _ => true, @@ -138,7 +135,7 @@ impl<T: fmt::Debug + Clone + Eq + Set<U>, U: fmt::Debug + Clone + Eq> Set<Constr } } -impl<T: fmt::Debug + Clone + Eq + PartialEq> From<Option<T>> for Constraint<T> { +impl<T> From<Option<T>> for Constraint<T> { fn from(value: Option<T>) -> Self { match value { Some(value) => Constraint::Only(value), |
