From 8c3c8efa428200c67c1a6fa731faee55adf19678 Mon Sep 17 00:00:00 2001 From: Nathan Reiner Date: Thu, 6 Jul 2023 14:05:39 +0200 Subject: cleanup with clippy --- src/dictionary.rs | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) (limited to 'src/dictionary.rs') diff --git a/src/dictionary.rs b/src/dictionary.rs index b522c9e..e0a561a 100644 --- a/src/dictionary.rs +++ b/src/dictionary.rs @@ -6,6 +6,11 @@ pub struct Dictionary { data : HashMap, } +impl Default for Dictionary { + fn default() -> Self { + Self::new() + } +} impl Dictionary { pub fn new() -> Self { @@ -25,9 +30,9 @@ impl Dictionary { } pub fn set(&mut self, name : String) { - if !self.data.contains_key(&name) { + if let std::collections::hash_map::Entry::Vacant(e) = self.data.entry(name) { self.last_index += 1; - self.data.insert(name, self.last_index as u64); + e.insert(self.last_index as u64); } } -- cgit v1.2.3-70-g09d2