Impl get, contains, insert, replace, remove & take

for `binstall_v1::Records`

Signed-off-by: Jiahao XU <Jiahao_XU@outlook.com>
This commit is contained in:
Jiahao XU 2022-07-27 22:30:58 +10:00
parent 04f167491a
commit 8ec33c5b6c
No known key found for this signature in database
GPG key ID: 591C0B03040416D6

View file

@ -161,6 +161,34 @@ impl Records {
pub fn overwrite(self) -> Result<(), Error> { pub fn overwrite(self) -> Result<(), Error> {
write_to(self.file, &mut self.data.into_iter()) write_to(self.file, &mut self.data.into_iter())
} }
pub fn get(&self, value: impl AsRef<str>) -> Option<&MetaData> {
self.data.get(value.as_ref())
}
pub fn contains(&self, value: impl AsRef<str>) -> 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<MetaData> {
self.data.replace(value)
}
pub fn remove(&mut self, value: impl AsRef<str>) -> bool {
self.data.remove(value.as_ref())
}
pub fn take(&mut self, value: impl AsRef<str>) -> Option<MetaData> {
self.data.take(value.as_ref())
}
} }
impl<'a> IntoIterator for &'a Records { impl<'a> IntoIterator for &'a Records {