Skip to content

Commit

Permalink
Remove Set trait
Browse files Browse the repository at this point in the history
  • Loading branch information
Serock3 authored and MarkusPettersson98 committed Apr 4, 2024
1 parent 1fb587d commit c0b0304
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 50 deletions.
5 changes: 1 addition & 4 deletions mullvad-types/src/constraints/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<T> {
fn is_subset(&self, other: &T) -> bool;
}
use crate::relay_constraints;

pub trait Match<T> {
fn matches(&self, other: &T) -> bool;
Expand Down
47 changes: 1 addition & 46 deletions mullvad-types/src/relay_constraints.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -294,51 +294,6 @@ impl Match<Relay> for GeographicLocationConstraint {
}
}

impl Set<GeographicLocationConstraint> 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<Constraint<Vec<GeographicLocationConstraint>>>
for Constraint<Vec<GeographicLocationConstraint>>
{
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))]
Expand Down

0 comments on commit c0b0304

Please sign in to comment.