Signed-off-by: Stefan Hanreich <s.hanre...@proxmox.com> --- proxmox-ve-config/src/common/mod.rs | 30 +++++++++++++++++++++++++++++ proxmox-ve-config/src/lib.rs | 1 + 2 files changed, 31 insertions(+) create mode 100644 proxmox-ve-config/src/common/mod.rs
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>{ + Self::from_iter(iter) + } +} + diff --git a/proxmox-ve-config/src/lib.rs b/proxmox-ve-config/src/lib.rs index 856b14f..1b6feae 100644 --- a/proxmox-ve-config/src/lib.rs +++ b/proxmox-ve-config/src/lib.rs @@ -1,3 +1,4 @@ +pub mod common; pub mod firewall; pub mod guest; pub mod host; -- 2.39.2 _______________________________________________ pve-devel mailing list pve-devel@lists.proxmox.com https://lists.proxmox.com/cgi-bin/mailman/listinfo/pve-devel