From c0b0304be43f994dc661d18696085dbd415afb24 Mon Sep 17 00:00:00 2001 From: Sebastian Holmin Date: Tue, 2 Apr 2024 12:24:10 +0200 Subject: [PATCH] Remove `Set` trait --- mullvad-types/src/constraints/mod.rs | 5 +-- mullvad-types/src/relay_constraints.rs | 47 +------------------------- 2 files changed, 2 insertions(+), 50 deletions(-) diff --git a/mullvad-types/src/constraints/mod.rs b/mullvad-types/src/constraints/mod.rs index 8ee6e93195a5..756066c447fa 100644 --- a/mullvad-types/src/constraints/mod.rs +++ b/mullvad-types/src/constraints/mod.rs @@ -5,10 +5,7 @@ mod constraint; // Re-export bits & pieces from `constraints.rs` as needed pub use constraint::Constraint; -/// A limited variant of Sets. -pub trait Set { - fn is_subset(&self, other: &T) -> bool; -} +use crate::relay_constraints; pub trait Match { fn matches(&self, other: &T) -> bool; diff --git a/mullvad-types/src/relay_constraints.rs b/mullvad-types/src/relay_constraints.rs index dc6d0608e59e..9b6b640cf527 100644 --- a/mullvad-types/src/relay_constraints.rs +++ b/mullvad-types/src/relay_constraints.rs @@ -2,7 +2,7 @@ //! updated as well. use crate::{ - constraints::{Constraint, Match, Set}, + constraints::{Constraint, Match}, custom_list::{CustomListsSettings, Id}, location::{CityCode, CountryCode, Hostname}, relay_list::Relay, @@ -294,51 +294,6 @@ impl Match for GeographicLocationConstraint { } } -impl Set for GeographicLocationConstraint { - /// Returns whether `self` is equal to or a subset of `other`. - fn is_subset(&self, other: &Self) -> bool { - match self { - GeographicLocationConstraint::Country(_) => self == other, - GeographicLocationConstraint::City(ref country, ref _city) => match other { - GeographicLocationConstraint::Country(ref other_country) => { - country == other_country - } - GeographicLocationConstraint::City(..) => self == other, - _ => false, - }, - GeographicLocationConstraint::Hostname(ref country, ref city, ref _hostname) => { - match other { - GeographicLocationConstraint::Country(ref other_country) => { - country == other_country - } - GeographicLocationConstraint::City(ref other_country, ref other_city) => { - country == other_country && city == other_city - } - GeographicLocationConstraint::Hostname(..) => self == other, - } - } - } - } -} - -impl Set>> - for Constraint> -{ - fn is_subset(&self, other: &Self) -> bool { - match self { - Constraint::Any => other.is_any(), - Constraint::Only(locations) => match other { - Constraint::Any => true, - Constraint::Only(other_locations) => locations.iter().all(|location| { - other_locations - .iter() - .any(|other_location| location.is_subset(other_location)) - }), - }, - } - } -} - /// Limits the set of servers to choose based on ownership. #[derive(Debug, Copy, Clone, Eq, PartialEq, Deserialize, Serialize)] #[cfg_attr(target_os = "android", derive(IntoJava, FromJava))]