MatchList::with_capacity and Into<Vec<MatchEntry>>

Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
This commit is contained in:
Wolfgang Bumiller 2020-04-27 16:54:38 +02:00
parent d5c0e44a9d
commit 96d7b7c74d

View File

@ -214,10 +214,19 @@ impl MatchList {
Self { list: list.into() } Self { list: list.into() }
} }
/// Create a new empty list with a specified maximum capacity.
pub fn with_capacity(capacity: usize) -> Self {
Self {
list: Vec::with_capacity(capacity)
}
}
/// Add another entry.
pub fn push(&mut self, entry: MatchEntry) { pub fn push(&mut self, entry: MatchEntry) {
self.list.push(entry) self.list.push(entry)
} }
/// Remove the list entry.
pub fn pop(&mut self) -> Option<MatchEntry> { pub fn pop(&mut self) -> Option<MatchEntry> {
self.list.pop() self.list.pop()
} }
@ -229,6 +238,12 @@ impl From<Vec<MatchEntry>> for MatchList {
} }
} }
impl Into<Vec<MatchEntry>> for MatchList {
fn into(self) -> Vec<MatchEntry> {
self.list
}
}
impl std::ops::Deref for MatchList { impl std::ops::Deref for MatchList {
type Target = MatchListRef; type Target = MatchListRef;