From 96d7b7c74d37a2d5ab7b6045824911d55df7cfea Mon Sep 17 00:00:00 2001 From: Wolfgang Bumiller Date: Mon, 27 Apr 2020 16:54:38 +0200 Subject: [PATCH] MatchList::with_capacity and Into> Signed-off-by: Wolfgang Bumiller --- src/match_list.rs | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/match_list.rs b/src/match_list.rs index 4c43d23..3bbaeca 100644 --- a/src/match_list.rs +++ b/src/match_list.rs @@ -214,10 +214,19 @@ impl MatchList { 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) { self.list.push(entry) } + /// Remove the list entry. pub fn pop(&mut self) -> Option { self.list.pop() } @@ -229,6 +238,12 @@ impl From> for MatchList { } } +impl Into> for MatchList { + fn into(self) -> Vec { + self.list + } +} + impl std::ops::Deref for MatchList { type Target = MatchListRef;