diff options
| author | KyleMiles <krm504@nyu.edu> | 2023-01-05 17:29:14 -0500 |
|---|---|---|
| committer | KyleMiles <krm504@nyu.edu> | 2023-01-06 16:29:58 -0500 |
| commit | a154e45cce79b0c2264c1e1cd37a3d1bf5bc6154 (patch) | |
| tree | 11f436b720edfdf37819e9e83e7131d220687074 /rust/src/symbol.rs | |
| parent | 52edc39a7081fd6662e14fbcd473adabbbc36c7a (diff) | |
Rust API: Lots and lots of clippy changes
Diffstat (limited to 'rust/src/symbol.rs')
| -rw-r--r-- | rust/src/symbol.rs | 35 |
1 files changed, 25 insertions, 10 deletions
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<S: BnStrCompatible> { } impl<S: BnStrCompatible> SymbolBuilder<S> { + 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<S: BnStrCompatible> SymbolBuilder<S> { } } -#[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>`: + /// + /// ``` + /// Symbol::new().short_name("hello").full_name("hello").create(); + /// ``` pub fn new<S: BnStrCompatible>(ty: SymbolType, raw_name: S, addr: u64) -> SymbolBuilder<S> { - 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<H: Hasher>(&self, state: &mut H) { + self.handle.hash(state); + } +} + impl PartialEq for Symbol { fn eq(&self, other: &Self) -> bool { self.handle == other.handle |
