From a154e45cce79b0c2264c1e1cd37a3d1bf5bc6154 Mon Sep 17 00:00:00 2001 From: KyleMiles Date: Thu, 5 Jan 2023 17:29:14 -0500 Subject: Rust API: Lots and lots of clippy changes --- rust/src/symbol.rs | 35 +++++++++++++++++++++++++---------- 1 file changed, 25 insertions(+), 10 deletions(-) (limited to 'rust/src/symbol.rs') diff --git a/rust/src/symbol.rs b/rust/src/symbol.rs index 5b1d62a1..0b3ef224 100644 --- a/rust/src/symbol.rs +++ b/rust/src/symbol.rs @@ -113,6 +113,18 @@ pub struct SymbolBuilder { } impl SymbolBuilder { + pub fn new(ty: SymbolType, raw_name: S, addr: u64) -> Self { + Self { + ty, + binding: Binding::None, + addr, + raw_name, + short_name: None, + full_name: None, + ordinal: 0, + } + } + pub fn binding(mut self, binding: Binding) -> Self { self.binding = binding; self @@ -163,7 +175,6 @@ impl SymbolBuilder { } } -#[derive(Hash)] pub struct Symbol { pub(crate) handle: *mut BNSymbol, } @@ -173,16 +184,14 @@ impl Symbol { Self { handle: raw } } + #[allow(clippy::new_ret_no_self)] + /// To create a new symbol, you need to create a symbol builder, customize that symbol, then add `SymbolBuilder::create` it into a `Ref`: + /// + /// ``` + /// Symbol::new().short_name("hello").full_name("hello").create(); + /// ``` pub fn new(ty: SymbolType, raw_name: S, addr: u64) -> SymbolBuilder { - SymbolBuilder { - ty: ty, - binding: Binding::None, - addr: addr, - raw_name: raw_name, - short_name: None, - full_name: None, - ordinal: 0, - } + SymbolBuilder::new(ty, raw_name, addr) } pub fn sym_type(&self) -> SymbolType { @@ -278,6 +287,12 @@ unsafe impl<'a> CoreArrayWrapper<'a> for Symbol { } } +impl Hash for Symbol { + fn hash(&self, state: &mut H) { + self.handle.hash(state); + } +} + impl PartialEq for Symbol { fn eq(&self, other: &Self) -> bool { self.handle == other.handle -- cgit v1.3.1