From 9ea6ece0fbe639fac9f6f697a71bcc74942de92e Mon Sep 17 00:00:00 2001 From: Worapol Worakunsap Date: Thu, 16 Nov 2023 11:34:57 +0700 Subject: [PATCH] fix: clippy cleaning --- src/config.rs | 3 +-- src/enforcer.rs | 6 +++--- src/rbac/default_role_manager.rs | 7 ++----- 3 files changed, 6 insertions(+), 10 deletions(-) diff --git a/src/config.rs b/src/config.rs index 9566c054..a8a3d211 100644 --- a/src/config.rs +++ b/src/config.rs @@ -151,8 +151,7 @@ impl Config { if section.is_empty() { section = DEFAULT_SECTION.to_owned(); } - let section_value = - self.data.entry(section).or_insert_with(HashMap::new); + let section_value = self.data.entry(section).or_default(); // if key not exists then insert, else update let key_value = section_value.get_mut(&option); diff --git a/src/enforcer.rs b/src/enforcer.rs index e41b528c..8bf4a13a 100644 --- a/src/enforcer.rs +++ b/src/enforcer.rs @@ -100,7 +100,7 @@ impl EnforceContext { impl EventEmitter for Enforcer { fn on(&mut self, e: Event, f: fn(&mut Self, EventData)) { - self.events.entry(e).or_insert_with(Vec::new).push(f) + self.events.entry(e).or_default().push(f) } fn off(&mut self, e: Event) { @@ -151,7 +151,7 @@ impl Enforcer { self.eft.new_stream(&e_ast.value, max(policy_len, 1)); let m_ast_compiled = self .engine - .compile_expression(&escape_eval(&m_ast.value)) + .compile_expression(escape_eval(&m_ast.value)) .map_err(Into::>::into)?; if policy_len == 0 { @@ -280,7 +280,7 @@ impl Enforcer { self.eft.new_stream(&e_ast.value, max(policy_len, 1)); let m_ast_compiled = self .engine - .compile_expression(&escape_eval(&m_ast.value)) + .compile_expression(escape_eval(&m_ast.value)) .map_err(Into::>::into)?; if policy_len == 0 { diff --git a/src/rbac/default_role_manager.rs b/src/rbac/default_role_manager.rs index 3e632c58..e61bee31 100644 --- a/src/rbac/default_role_manager.rs +++ b/src/rbac/default_role_manager.rs @@ -53,15 +53,12 @@ impl DefaultRoleManager { ) -> NodeIndex { let domain = domain.unwrap_or(DEFAULT_DOMAIN); - let graph = self - .all_domains - .entry(domain.into()) - .or_insert_with(StableDiGraph::new); + let graph = self.all_domains.entry(domain.into()).or_default(); let role_entry = self .all_domains_indices .entry(domain.into()) - .or_insert_with(HashMap::new) + .or_default() .entry(name.into()); let vacant_entry = match role_entry {