From 8ec33c5b6c058556bbce0a9fb5882c4c31a40581 Mon Sep 17 00:00:00 2001 From: Jiahao XU Date: Wed, 27 Jul 2022 22:30:58 +1000 Subject: [PATCH] Impl get, contains, insert, replace, remove & take for `binstall_v1::Records` Signed-off-by: Jiahao XU --- src/metafiles/binstall_v1.rs | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/src/metafiles/binstall_v1.rs b/src/metafiles/binstall_v1.rs index edb9c61c..02fdf167 100644 --- a/src/metafiles/binstall_v1.rs +++ b/src/metafiles/binstall_v1.rs @@ -161,6 +161,34 @@ impl Records { pub fn overwrite(self) -> Result<(), Error> { write_to(self.file, &mut self.data.into_iter()) } + + pub fn get(&self, value: impl AsRef) -> Option<&MetaData> { + self.data.get(value.as_ref()) + } + + pub fn contains(&self, value: impl AsRef) -> bool { + self.data.contains(value.as_ref()) + } + + /// Adds a value to the set. + /// If the set did not have an equal element present, true is returned. + /// + /// If the set did have an equal element present, false is returned, and the entry is not updated. See the module-level documentation for more. + pub fn insert(&mut self, value: MetaData) -> bool { + self.data.insert(value) + } + + pub fn replace(&mut self, value: MetaData) -> Option { + self.data.replace(value) + } + + pub fn remove(&mut self, value: impl AsRef) -> bool { + self.data.remove(value.as_ref()) + } + + pub fn take(&mut self, value: impl AsRef) -> Option { + self.data.take(value.as_ref()) + } } impl<'a> IntoIterator for &'a Records {