From 5b51a4ff188c426d8f90ac71ee6dde0fa3b5a495 Mon Sep 17 00:00:00 2001 From: Michael Krasnitski Date: Fri, 6 Jan 2023 02:04:49 -0500 Subject: Clean up various builders --- rust/src/section.rs | 22 +++++++--------------- 1 file changed, 7 insertions(+), 15 deletions(-) (limited to 'rust/src/section.rs') diff --git a/rust/src/section.rs b/rust/src/section.rs index 49642b4d..971204ba 100644 --- a/rust/src/section.rs +++ b/rust/src/section.rs @@ -70,13 +70,12 @@ 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 { + pub fn builder(name: S, range: Range) -> SectionBuilder { SectionBuilder::new(name, range) } @@ -204,7 +203,7 @@ pub struct SectionBuilder { impl SectionBuilder { pub fn new(name: S, range: Range) -> Self { - SectionBuilder { + Self { is_auto: false, name, range, @@ -268,19 +267,12 @@ impl SectionBuilder { let len = self.range.end.wrapping_sub(start); unsafe { - use std::ffi::CStr; - - let nul_str = CStr::from_bytes_with_nul_unchecked(b"\x00").as_ptr(); + let nul_str = std::ffi::CStr::from_bytes_with_nul_unchecked(b"\x00").as_ptr(); let name_ptr = name.as_ref().as_ptr() as *mut _; - let ty_ptr = ty - .as_ref() - .map_or(nul_str, |s| s.as_ref().as_ptr() as *mut _); - let linked_section_ptr = linked_section - .as_ref() - .map_or(nul_str, |s| s.as_ref().as_ptr() as *mut _); - let info_section_ptr = info_section - .as_ref() - .map_or(nul_str, |s| s.as_ref().as_ptr() as *mut _); + let ty_ptr = ty.map_or(nul_str, |s| s.as_ref().as_ptr() as *mut _); + let linked_section_ptr = + linked_section.map_or(nul_str, |s| s.as_ref().as_ptr() as *mut _); + let info_section_ptr = info_section.map_or(nul_str, |s| s.as_ref().as_ptr() as *mut _); if self.is_auto { BNAddAutoSection( -- cgit v1.3.1