Skip to content

Commit

Permalink
feat: Allow clearing table-likes
Browse files Browse the repository at this point in the history
  • Loading branch information
epage committed Jan 27, 2022
1 parent 68f8a53 commit b4d4ee1
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 0 deletions.
3 changes: 3 additions & 0 deletions src/inline_table.rs
Original file line number Diff line number Diff line change
Expand Up @@ -395,6 +395,9 @@ impl TableLike for InlineTable {
.map(|(_, kv)| (kv.key.as_mut(), &mut kv.value)),
)
}
fn clear(&mut self) {
self.clear();
}
fn get<'s>(&'s self, key: &str) -> Option<&'s Item> {
self.items.get(key).map(|kv| &kv.value)
}
Expand Down
5 changes: 5 additions & 0 deletions src/table.rs
Original file line number Diff line number Diff line change
Expand Up @@ -469,6 +469,8 @@ pub trait TableLike: crate::private::Sealed {
fn is_empty(&self) -> bool {
self.len() == 0
}
/// Clears the table, removing all key-value pairs. Keeps the allocated memory for reuse.
fn clear(&mut self);
/// Returns an optional reference to an item given the key.
fn get<'s>(&'s self, key: &str) -> Option<&'s Item>;
/// Returns an optional mutable reference to an item given the key.
Expand Down Expand Up @@ -509,6 +511,9 @@ impl TableLike for Table {
fn iter_mut(&mut self) -> IterMut<'_> {
self.iter_mut()
}
fn clear(&mut self) {
self.clear();
}
fn get<'s>(&'s self, key: &str) -> Option<&'s Item> {
self.get(key)
}
Expand Down

0 comments on commit b4d4ee1

Please sign in to comment.