From 81ccfc0be832d395899feaef7fe4b137958cc929 Mon Sep 17 00:00:00 2001 From: Ferran Borreguero Date: Mon, 6 Jan 2025 08:41:59 +0000 Subject: [PATCH] Use deref methods --- crates/rbuilder/src/blocklist/mod.rs | 27 ++++++++++----------------- 1 file changed, 10 insertions(+), 17 deletions(-) diff --git a/crates/rbuilder/src/blocklist/mod.rs b/crates/rbuilder/src/blocklist/mod.rs index 4f1c38a3..5b2c9b53 100644 --- a/crates/rbuilder/src/blocklist/mod.rs +++ b/crates/rbuilder/src/blocklist/mod.rs @@ -3,7 +3,7 @@ use alloy_primitives::Address; use serde::{Deserialize, Deserializer}; use std::convert::TryFrom; use std::fs::read_to_string; -use std::ops::Deref; +use std::ops::{Deref, DerefMut}; use std::path::PathBuf; #[allow(clippy::len_without_is_empty)] @@ -27,19 +27,6 @@ impl BlockList { list: blocklist.into_iter().collect(), }) } - - pub fn len(&self) -> usize { - self.list.len() - } - - pub fn contains(&self, address: &Address) -> bool { - self.list.contains(address) - } - - #[cfg(test)] - fn add(&mut self, address: Address) { - self.list.insert(address); - } } impl TryFrom for BlockList { @@ -66,6 +53,12 @@ impl Deref for BlockList { } } +impl DerefMut for BlockList { + fn deref_mut(&mut self) -> &mut Self::Target { + &mut self.list + } +} + impl<'de> Deserialize<'de> for BlockList { fn deserialize(deserializer: D) -> Result where @@ -108,18 +101,18 @@ mod test { let mut blocklist = BlockList::new(); let addr0 = Address::random(); - blocklist.add(addr0); + blocklist.insert(addr0); assert_eq!(blocklist.len(), 1); assert_eq!(blocklist.contains(&addr0), true); // you cannot add twice the same value - blocklist.add(addr0); + blocklist.insert(addr0); assert_eq!(blocklist.len(), 1); let addr1 = Address::random(); assert_eq!(blocklist.contains(&addr1), false); - blocklist.add(addr1); + blocklist.insert(addr1); assert_eq!(blocklist.len(), 2); assert_eq!(blocklist.contains(&addr1), true); }