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/section.rs | 38 ++++++++++++++++++++++++++------------ 1 file changed, 26 insertions(+), 12 deletions(-) (limited to 'rust/src/section.rs') diff --git a/rust/src/section.rs b/rust/src/section.rs index 4eb49e69..b73809c0 100644 --- a/rust/src/section.rs +++ b/rust/src/section.rs @@ -70,19 +70,14 @@ impl Section { Self { handle: raw } } + #[allow(clippy::new_ret_no_self)] + /// You need to create a section builder, customize that section, then add it to a binary view: + /// + /// ``` + /// bv.add_section(Section::new().align(4).entry_size(4)) + /// ``` pub fn new(name: S, range: Range) -> SectionBuilder { - SectionBuilder { - is_auto: false, - name: name, - range: range, - semantics: Semantics::DefaultSection, - _ty: None, - align: 1, - entry_size: 1, - linked_section: None, - info_section: None, - info_data: 0, - } + SectionBuilder::new(name, range) } pub fn name(&self) -> BnString { @@ -105,6 +100,10 @@ impl Section { unsafe { BNSectionGetLength(self.handle) as usize } } + pub fn is_empty(&self) -> bool { + unsafe { BNSectionGetLength(self.handle) as usize == 0 } + } + pub fn address_range(&self) -> Range { self.start()..self.end() } @@ -204,6 +203,21 @@ pub struct SectionBuilder { } impl SectionBuilder { + pub fn new(name: S, range: Range) -> Self { + SectionBuilder { + is_auto: false, + name, + range, + semantics: Semantics::DefaultSection, + _ty: None, + align: 1, + entry_size: 1, + linked_section: None, + info_section: None, + info_data: 0, + } + } + pub fn semantics(mut self, semantics: Semantics) -> Self { self.semantics = semantics; self -- cgit v1.3.1