[pve-devel] [PATCH proxmox-ve-rs 08/21] common: add allowlist

Gabriel Goller g.goller at proxmox.com
Thu Jun 27 12:47:08 CEST 2024


On 26.06.2024 14:15, Stefan Hanreich wrote:
>diff --git a/proxmox-ve-config/src/common/mod.rs b/proxmox-ve-config/src/common/mod.rs
>new file mode 100644
>index 0000000..9318cff
>--- /dev/null
>+++ b/proxmox-ve-config/src/common/mod.rs
>@@ -0,0 +1,30 @@
>+use core::hash::Hash;
>+use std::cmp::Eq;
>+use std::collections::HashSet;
>+
>+#[derive(Clone, Debug, Default)]
>+pub struct Allowlist<T>(HashSet<T>);
>+
>+impl<T: Hash + Eq> FromIterator<T> for Allowlist<T> {
>+    fn from_iter<A>(iter: A) -> Self
>+    where
>+        A: IntoIterator<Item = T>,
>+    {
>+        Allowlist(HashSet::from_iter(iter))
>+    }
>+}
>+
>+/// returns true if [`value`] is in the allowlist or if allowlist does not exist
>+impl<T: Hash + Eq> Allowlist<T> {
>+    pub fn is_allowed(&self, value: &T) -> bool {
>+        self.0.contains(value)
>+    }
>+}
>+
>+impl<T: Hash + Eq> Allowlist<T> {
>+    pub fn new<I>(iter: I) -> Self
>+    where I: IntoIterator<Item = T>{

^ Small rustfmt error here.

>+        Self::from_iter(iter)
>+    }
>+}
>+




More information about the pve-devel mailing list