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/types.rs | 66 +++++++++++++++++++++++++++++++++++-------------------- 1 file changed, 42 insertions(+), 24 deletions(-) (limited to 'rust/src/types.rs') diff --git a/rust/src/types.rs b/rust/src/types.rs index c7f55b8f..a8f023ad 100644 --- a/rust/src/types.rs +++ b/rust/src/types.rs @@ -310,13 +310,13 @@ impl TypeBuilder { // Settable properties - pub fn set_const<'a, T: Into>>(&'a mut self, value: T) -> &'a mut Self { + pub fn set_const>>(&mut self, value: T) -> &mut Self { let mut bool_with_confidence = value.into().into(); unsafe { BNTypeBuilderSetConst(self.handle, &mut bool_with_confidence) }; self } - pub fn set_volatile<'a, T: Into>>(&'a mut self, value: T) -> &'a mut Self { + pub fn set_volatile>>(&mut self, value: T) -> &mut Self { let mut bool_with_confidence = value.into().into(); unsafe { BNTypeBuilderSetVolatile(self.handle, &mut bool_with_confidence) }; self @@ -621,7 +621,7 @@ impl TypeBuilder { &t.into().into(), &mut is_const, &mut is_volatile, - ref_type.unwrap_or_else(|| ReferenceType::PointerReferenceType), + ref_type.unwrap_or(ReferenceType::PointerReferenceType), )) } } @@ -641,7 +641,7 @@ impl TypeBuilder { &t.into().into(), &mut is_const, &mut is_volatile, - ref_type.unwrap_or_else(|| ReferenceType::PointerReferenceType), + ref_type.unwrap_or(ReferenceType::PointerReferenceType), )) } } @@ -664,7 +664,7 @@ impl Drop for TypeBuilder { ////////// // Type -#[derive(Eq, Hash)] +#[derive(Eq)] pub struct Type { pub(crate) handle: *mut BNType, } @@ -978,7 +978,7 @@ impl Type { for parameter in parameters { let raw_name = parameter.name.clone().into_bytes_with_nul(); let location = match ¶meter.location { - Some(location) => location.into_raw(), + Some(location) => location.raw(), None => unsafe { mem::zeroed() }, }; @@ -1048,7 +1048,7 @@ impl Type { for (name, parameter) in zip(name_ptrs, parameters) { let raw_name = name.into_bytes_with_nul(); let location = match ¶meter.location { - Some(location) => location.into_raw(), + Some(location) => location.raw(), None => unsafe { mem::zeroed() }, }; @@ -1136,7 +1136,7 @@ impl Type { &t.into().into(), &mut is_const, &mut is_volatile, - ref_type.unwrap_or_else(|| ReferenceType::PointerReferenceType), + ref_type.unwrap_or(ReferenceType::PointerReferenceType), )) } } @@ -1156,7 +1156,7 @@ impl Type { &t.into().into(), &mut is_const, &mut is_volatile, - ref_type.unwrap_or_else(|| ReferenceType::PointerReferenceType), + ref_type.unwrap_or(ReferenceType::PointerReferenceType), )) } } @@ -1216,7 +1216,7 @@ impl fmt::Debug for Type { for (i, line) in line_slice.iter().enumerate() { if i > 0 { - write!(f, "\n")?; + writeln!(f)?; } let tokens: &[BNInstructionTextToken] = @@ -1245,6 +1245,12 @@ impl PartialEq for Type { } } +impl Hash for Type { + fn hash(&self, state: &mut H) { + self.handle.hash(state); + } +} + unsafe impl Send for Type {} unsafe impl Sync for Type {} @@ -1276,7 +1282,7 @@ pub struct FunctionParameter { pub location: Option, } -impl<'a, S: BnStrCompatible> FunctionParameter { +impl FunctionParameter { pub fn new>>>(t: T, name: S, location: Option) -> Self { Self { t: t.into(), @@ -1305,7 +1311,7 @@ impl FunctionParameter { unsafe { Type::ref_from_raw(BNNewTypeReference(handle.type_)) }, handle.typeConfidence, ), - name: name, + name, location: if handle.defaultLocation { None } else { @@ -1338,7 +1344,7 @@ impl Variable { } } - pub(crate) fn into_raw(&self) -> BNVariable { + pub(crate) fn raw(&self) -> BNVariable { BNVariable { type_: self.t, index: self.index, @@ -1395,7 +1401,7 @@ impl EnumerationBuilder { Enumeration::new(self) } - pub fn append<'a, S: BnStrCompatible>(&'a mut self, name: S) -> &'a mut Self { + pub fn append(&mut self, name: S) -> &mut Self { let name = name.into_bytes_with_nul(); unsafe { BNAddEnumerationBuilderMember(self.handle, name.as_ref().as_ptr() as _); @@ -1403,7 +1409,7 @@ impl EnumerationBuilder { self } - pub fn insert<'a, S: BnStrCompatible>(&'a mut self, name: S, value: u64) -> &'a mut Self { + pub fn insert(&mut self, name: S, value: u64) -> &mut Self { let name = name.into_bytes_with_nul(); unsafe { BNAddEnumerationBuilderMemberWithValue(self.handle, name.as_ref().as_ptr() as _, value); @@ -1411,12 +1417,12 @@ impl EnumerationBuilder { self } - pub fn replace<'a, S: BnStrCompatible>( - &'a mut self, + pub fn replace( + &mut self, id: usize, name: S, value: u64, - ) -> &'a mut Self { + ) -> &mut Self { let name = name.into_bytes_with_nul(); unsafe { BNReplaceEnumerationBuilderMember(self.handle, id, name.as_ref().as_ptr() as _, value); @@ -1424,7 +1430,7 @@ impl EnumerationBuilder { self } - pub fn remove<'a>(&'a mut self, id: usize) -> &'a mut Self { + pub fn remove(&mut self, id: usize) -> &mut Self { unsafe { BNRemoveEnumerationBuilderMember(self.handle, id); } @@ -1450,6 +1456,12 @@ impl EnumerationBuilder { } } +impl Default for EnumerationBuilder { + fn default() -> Self { + Self::new() + } +} + impl From<&Enumeration> for EnumerationBuilder { fn from(enumeration: &Enumeration) -> Self { unsafe { @@ -1586,7 +1598,7 @@ impl StructureBuilder { // Chainable builders/setters - pub fn set_width<'a>(&'a mut self, width: u64) -> &'a mut Self { + pub fn set_width(&mut self, width: u64) -> &mut Self { unsafe { BNSetStructureBuilderWidth(self.handle, width); } @@ -1594,7 +1606,7 @@ impl StructureBuilder { self } - pub fn set_alignment<'a>(&'a mut self, alignment: usize) -> &'a mut Self { + pub fn set_alignment(&mut self, alignment: usize) -> &mut Self { unsafe { BNSetStructureBuilderAlignment(self.handle, alignment); } @@ -1602,7 +1614,7 @@ impl StructureBuilder { self } - pub fn set_packed<'a>(&'a mut self, packed: bool) -> &'a mut Self { + pub fn set_packed(&mut self, packed: bool) -> &mut Self { unsafe { BNSetStructureBuilderPacked(self.handle, packed); } @@ -1673,7 +1685,7 @@ impl StructureBuilder { self } - pub fn set_structure_type<'a>(&'a mut self, t: StructureType) -> &'a Self { + pub fn set_structure_type(&mut self, t: StructureType) -> &Self { unsafe { BNSetStructureBuilderType(self.handle, t) }; self } @@ -1727,6 +1739,12 @@ impl Drop for StructureBuilder { } } +impl Default for StructureBuilder { + fn default() -> Self { + Self::new() + } +} + /////////////// // Structure @@ -2103,7 +2121,7 @@ impl NameAndType { impl NameAndType { pub fn new(name: S, t: &Ref, confidence: u8) -> Self { Self { - name: name, + name, t: Conf::new(t.clone(), confidence), } } -- cgit v1.3.1