summaryrefslogtreecommitdiff
path: root/rust
diff options
context:
space:
mode:
authorGlenn Smith <glenn@vector35.com>2022-08-29 22:43:59 -0400
committerGlenn Smith <glenn@vector35.com>2022-09-29 21:02:22 -0400
commit8cbdc0e05adefd58e6939f7bb70d6f031277e4f6 (patch)
tree439ddd7a8eddaca0a54bb980f1ce8b46dc57399d /rust
parent9fd6ed156fb926c64420c1b38b4e27f0e5c17d0a (diff)
[Rust API]: Eq for Ref<Type>
Diffstat (limited to 'rust')
-rw-r--r--rust/src/rc.rs8
-rw-r--r--rust/src/string.rs15
-rw-r--r--rust/src/symbol.rs7
-rw-r--r--rust/src/types.rs9
4 files changed, 30 insertions, 9 deletions
diff --git a/rust/src/rc.rs b/rust/src/rc.rs
index a65403e2..ad9d9e35 100644
--- a/rust/src/rc.rs
+++ b/rust/src/rc.rs
@@ -112,6 +112,14 @@ impl<T: RefCountable + Debug> Debug for Ref<T> {
}
}
+impl<T: RefCountable + PartialEq> PartialEq for Ref<T> {
+ fn eq(&self, other: &Self) -> bool {
+ self.contents.eq(&other.contents)
+ }
+}
+
+impl<T: RefCountable + PartialEq> Eq for Ref<T> {}
+
// Guard provides access to a core-allocated resource whose
// reference is held indirectly (e.g. a core-allocated array
// of raw `*mut BNRawT`).
diff --git a/rust/src/string.rs b/rust/src/string.rs
index 965d21f3..cff0fba7 100644
--- a/rust/src/string.rs
+++ b/rust/src/string.rs
@@ -261,16 +261,23 @@ unsafe impl BnStrCompatible for String {
type Result = Vec<u8>;
fn into_bytes_with_nul(self) -> Self::Result {
- let ret = CString::new(self).expect("can't pass strings with internal nul bytes to core!");
- ret.into_bytes_with_nul()
+ self.as_str().into_bytes_with_nul()
+ }
+}
+
+unsafe impl<'a> BnStrCompatible for &'a String {
+ type Result = Vec<u8>;
+
+ fn into_bytes_with_nul(self) -> Self::Result {
+ self.as_str().into_bytes_with_nul()
}
}
unsafe impl<'a> BnStrCompatible for &'a Cow<'a, str> {
- type Result = &'a [u8];
+ type Result = Vec<u8>;
fn into_bytes_with_nul(self) -> Self::Result {
- self.as_ref().as_bytes()
+ self.to_string().into_bytes_with_nul()
}
}
diff --git a/rust/src/symbol.rs b/rust/src/symbol.rs
index 21ae440e..2d5df068 100644
--- a/rust/src/symbol.rs
+++ b/rust/src/symbol.rs
@@ -163,7 +163,7 @@ impl<S: BnStrCompatible> SymbolBuilder<S> {
}
}
-#[derive(PartialEq, Eq, Hash)]
+#[derive(Hash)]
pub struct Symbol {
pub(crate) handle: *mut BNSymbol,
}
@@ -278,12 +278,11 @@ unsafe impl<'a> CoreArrayWrapper<'a> for Symbol {
}
}
-impl PartialEq for Ref<Symbol> {
+impl PartialEq for Symbol {
fn eq(&self, other: &Self) -> bool {
- **self == **other
+ *self == *other
}
}
-impl Eq for Ref<Symbol> {}
impl Hash for Ref<Symbol> {
fn hash<H: Hasher>(&self, state: &mut H) {
diff --git a/rust/src/types.rs b/rust/src/types.rs
index 746142a5..0a558228 100644
--- a/rust/src/types.rs
+++ b/rust/src/types.rs
@@ -579,7 +579,7 @@ impl Drop for TypeBuilder {
//////////
// Type
-#[derive(PartialEq, Eq, Hash)]
+#[derive(Eq, Hash)]
pub struct Type {
pub(crate) handle: *mut BNType,
}
@@ -1112,6 +1112,12 @@ impl fmt::Debug for Type {
}
}
+impl PartialEq for Type {
+ fn eq(&self, other: &Self) -> bool {
+ unsafe { BNTypesEqual(self.handle, other.handle) }
+ }
+}
+
unsafe impl Send for Type {}
unsafe impl Sync for Type {}
@@ -1217,6 +1223,7 @@ impl Variable {
////////////////////////
// EnumerationBuilder
+#[derive(Debug, Clone)]
pub struct EnumerationMember {
pub name: BnString,
pub value: u64,