diff options
| author | Sebastian Holmin <sebastian.holmin@mullvad.net> | 2024-09-16 10:59:39 +0200 |
|---|---|---|
| committer | Sebastian Holmin <sebastian.holmin@mullvad.net> | 2024-09-16 14:29:46 +0200 |
| commit | 281438b4218d96bfcefad85ac5b06297eaad1827 (patch) | |
| tree | 4c2ea196b41b762cc17b3774c5ab2c736599cb72 | |
| parent | aa61b9a4fa047e6027edc2d980942d4a5993ba3c (diff) | |
| download | mullvadvpn-281438b4218d96bfcefad85ac5b06297eaad1827.tar.xz mullvadvpn-281438b4218d96bfcefad85ac5b06297eaad1827.zip | |
Add `Display` and `is_empty` to `FeatureIndicators`
| -rw-r--r-- | mullvad-types/src/features.rs | 32 |
1 files changed, 27 insertions, 5 deletions
diff --git a/mullvad-types/src/features.rs b/mullvad-types/src/features.rs index 5cefbc9ea3..f847c94af0 100644 --- a/mullvad-types/src/features.rs +++ b/mullvad-types/src/features.rs @@ -1,4 +1,4 @@ -use std::collections::HashSet; +use std::{collections::HashSet, fmt::Display}; use crate::settings::{DnsState, Settings}; use serde::{Deserialize, Serialize}; @@ -11,6 +11,22 @@ use talpid_types::net::{ObfuscationType, TunnelEndpoint, TunnelType}; #[derive(Default, Debug, Clone, PartialEq, Eq, Serialize, Deserialize)] pub struct FeatureIndicators(HashSet<FeatureIndicator>); +impl FeatureIndicators { + pub fn is_empty(&self) -> bool { + self.0.is_empty() + } +} + +impl Display for FeatureIndicators { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + let mut indicators: Vec<&str> = self.0.iter().map(|feature| feature.to_str()).collect(); + // Sort the features alphabetically (Just to have some order, arbitrarily chosen) + indicators.sort(); + + write!(f, "{}", indicators.join(", ")) + } +} + impl IntoIterator for FeatureIndicators { type Item = FeatureIndicator; type IntoIter = std::collections::hash_set::IntoIter<Self::Item>; @@ -52,9 +68,9 @@ pub enum FeatureIndicator { Daita, } -impl std::fmt::Display for FeatureIndicator { - fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { - let feature = match self { +impl FeatureIndicator { + const fn to_str(&self) -> &'static str { + match self { FeatureIndicator::QuantumResistance => "Quantum Resistance", FeatureIndicator::Multihop => "Multihop", FeatureIndicator::BridgeMode => "Bridge Mode", @@ -69,7 +85,13 @@ impl std::fmt::Display for FeatureIndicator { FeatureIndicator::CustomMtu => "Custom MTU", FeatureIndicator::CustomMssFix => "Custom MSS", FeatureIndicator::Daita => "DAITA", - }; + } + } +} + +impl std::fmt::Display for FeatureIndicator { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + let feature = self.to_str(); write!(f, "{feature}") } } |
