From ad7f5293db22e23d8d50077aa99f5d7a904092fc Mon Sep 17 00:00:00 2001 From: Michael Krasnitski Date: Fri, 6 Jan 2023 14:13:55 -0500 Subject: Rust API: Additional Cleanup --- rust/src/types.rs | 77 +++++++++++++++++++++++-------------------------------- 1 file changed, 32 insertions(+), 45 deletions(-) (limited to 'rust/src/types.rs') diff --git a/rust/src/types.rs b/rust/src/types.rs index d9b28b4c..75475b6e 100644 --- a/rust/src/types.rs +++ b/rust/src/types.rs @@ -244,47 +244,38 @@ impl From for Conf { } } -impl Into for Conf<&Type> { - fn into(self) -> BNTypeWithConfidence { - BNTypeWithConfidence { - type_: self.contents.handle, - confidence: self.confidence, - } - } -} - -impl Into for &Conf<&Type> { - fn into(self) -> BNTypeWithConfidence { - BNTypeWithConfidence { - type_: self.contents.handle, - confidence: self.confidence, +impl From> for BNTypeWithConfidence { + fn from(conf: Conf<&Type>) -> Self { + Self { + type_: conf.contents.handle, + confidence: conf.confidence, } } } -impl Into for Conf { - fn into(self) -> BNBoolWithConfidence { - BNBoolWithConfidence { - value: self.contents, - confidence: self.confidence, +impl From> for BNBoolWithConfidence { + fn from(conf: Conf) -> Self { + Self { + value: conf.contents, + confidence: conf.confidence, } } } -impl Into for Conf<&CallingConvention> { - fn into(self) -> BNCallingConventionWithConfidence { - BNCallingConventionWithConfidence { - convention: self.contents.handle, - confidence: self.confidence, +impl From>> for BNCallingConventionWithConfidence { + fn from(conf: Conf<&CallingConvention>) -> Self { + Self { + convention: conf.contents.handle, + confidence: conf.confidence, } } } -impl Into for Conf { - fn into(self) -> BNOffsetWithConfidence { - BNOffsetWithConfidence { - value: self.contents, - confidence: self.confidence, +impl From> for BNOffsetWithConfidence { + fn from(conf: Conf) -> Self { + Self { + value: conf.contents, + confidence: conf.confidence, } } } @@ -664,7 +655,6 @@ impl Drop for TypeBuilder { ////////// // Type -#[derive(Eq)] pub struct Type { pub(crate) handle: *mut BNType, } @@ -1245,6 +1235,8 @@ impl PartialEq for Type { } } +impl Eq for Type {} + impl Hash for Type { fn hash(&self, state: &mut H) { self.handle.hash(state); @@ -1417,12 +1409,7 @@ impl EnumerationBuilder { self } - pub fn replace( - &mut self, - id: usize, - name: S, - value: u64, - ) -> &mut Self { + pub fn replace(&self, id: usize, name: S, value: u64) -> &Self { let name = name.into_bytes_with_nul(); unsafe { BNReplaceEnumerationBuilderMember(self.handle, id, name.as_ref().as_ptr() as _, value); @@ -1622,7 +1609,7 @@ impl StructureBuilder { self } - pub fn append<'a, 'b, S: BnStrCompatible, T: Into>>( + pub fn append<'a, S: BnStrCompatible, T: Into>>( &'a self, t: T, name: S, @@ -1643,11 +1630,11 @@ impl StructureBuilder { self } - pub fn insert_member<'a, 'b>( - &'a mut self, - member: &'b StructureMember, + pub fn insert_member( + &mut self, + member: &StructureMember, overwrite_existing: bool, - ) -> &'a mut Self { + ) -> &mut Self { let ty = member.ty.clone(); self.insert( ty.as_ref(), @@ -1660,15 +1647,15 @@ impl StructureBuilder { self } - pub fn insert<'a, 'b, S: BnStrCompatible, T: Into>>( - &'a mut self, + pub fn insert<'a, S: BnStrCompatible, T: Into>>( + &mut self, t: T, name: S, offset: u64, overwrite_existing: bool, access: MemberAccess, scope: MemberScope, - ) -> &'a mut Self { + ) -> &mut Self { let name = name.into_bytes_with_nul(); unsafe { BNAddStructureBuilderMemberAtOffset( @@ -1967,7 +1954,7 @@ impl QualifiedName { pub fn join(&self) -> Cow { let join: *mut c_char = self.0.join; - unsafe { CStr::from_ptr(join).to_string_lossy() } + unsafe { CStr::from_ptr(join) }.to_string_lossy() } pub fn strings(&self) -> Vec> { -- cgit v1.3.1