summaryrefslogtreecommitdiff
path: root/rust/src/string.rs
diff options
context:
space:
mode:
authorGlenn Smith <glenn@vector35.com>2022-07-21 15:24:16 -0400
committerGlenn Smith <glenn@vector35.com>2022-09-29 21:02:22 -0400
commitd552ae9beae6404c13548b98ec7a7ec4e6b3dd90 (patch)
tree00a2696b2a3a33b1ac5bb058801fdea9f1a38c03 /rust/src/string.rs
parent2e18783a2f6e29c225d177e8a0fb866a9c9d85df (diff)
[Rust API] Better name for this trait fn, more CC support
Diffstat (limited to 'rust/src/string.rs')
-rw-r--r--rust/src/string.rs23
1 files changed, 12 insertions, 11 deletions
diff --git a/rust/src/string.rs b/rust/src/string.rs
index 42ff4fdc..965d21f3 100644
--- a/rust/src/string.rs
+++ b/rust/src/string.rs
@@ -99,7 +99,7 @@ impl BnString {
pub fn new<S: BnStrCompatible>(s: S) -> Self {
use binaryninjacore_sys::BNAllocString;
- let raw = s.as_bytes_with_nul();
+ let raw = s.into_bytes_with_nul();
unsafe {
let ptr = raw.as_ref().as_ptr() as *mut _;
@@ -110,6 +110,7 @@ impl BnString {
}
}
+ /// Construct a BnString from an owned const char* allocated by BNAllocString
pub(crate) unsafe fn from_raw(raw: *mut raw::c_char) -> Self {
Self { raw }
}
@@ -212,13 +213,13 @@ unsafe impl<'a> CoreArrayWrapper<'a> for BnString {
pub unsafe trait BnStrCompatible {
type Result: AsRef<[u8]>;
- fn as_bytes_with_nul(self) -> Self::Result;
+ fn into_bytes_with_nul(self) -> Self::Result;
}
unsafe impl<'a> BnStrCompatible for &'a BnStr {
type Result = &'a [u8];
- fn as_bytes_with_nul(self) -> Self::Result {
+ fn into_bytes_with_nul(self) -> Self::Result {
self.as_cstr().to_bytes_with_nul()
}
}
@@ -226,7 +227,7 @@ unsafe impl<'a> BnStrCompatible for &'a BnStr {
unsafe impl BnStrCompatible for BnString {
type Result = Self;
- fn as_bytes_with_nul(self) -> Self::Result {
+ fn into_bytes_with_nul(self) -> Self::Result {
self
}
}
@@ -234,7 +235,7 @@ unsafe impl BnStrCompatible for BnString {
unsafe impl<'a> BnStrCompatible for &'a CStr {
type Result = &'a [u8];
- fn as_bytes_with_nul(self) -> Self::Result {
+ fn into_bytes_with_nul(self) -> Self::Result {
self.to_bytes_with_nul()
}
}
@@ -242,7 +243,7 @@ unsafe impl<'a> BnStrCompatible for &'a CStr {
unsafe impl BnStrCompatible for CString {
type Result = Vec<u8>;
- fn as_bytes_with_nul(self) -> Self::Result {
+ fn into_bytes_with_nul(self) -> Self::Result {
self.into_bytes_with_nul()
}
}
@@ -250,7 +251,7 @@ unsafe impl BnStrCompatible for CString {
unsafe impl<'a> BnStrCompatible for &'a str {
type Result = Vec<u8>;
- fn as_bytes_with_nul(self) -> Self::Result {
+ 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()
}
@@ -259,7 +260,7 @@ unsafe impl<'a> BnStrCompatible for &'a str {
unsafe impl BnStrCompatible for String {
type Result = Vec<u8>;
- fn as_bytes_with_nul(self) -> Self::Result {
+ 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()
}
@@ -268,7 +269,7 @@ unsafe impl BnStrCompatible for String {
unsafe impl<'a> BnStrCompatible for &'a Cow<'a, str> {
type Result = &'a [u8];
- fn as_bytes_with_nul(self) -> Self::Result {
+ fn into_bytes_with_nul(self) -> Self::Result {
self.as_ref().as_bytes()
}
}
@@ -276,7 +277,7 @@ unsafe impl<'a> BnStrCompatible for &'a Cow<'a, str> {
unsafe impl BnStrCompatible for &QualifiedName {
type Result = Vec<u8>;
- fn as_bytes_with_nul(self) -> Self::Result {
- self.string().as_bytes_with_nul()
+ fn into_bytes_with_nul(self) -> Self::Result {
+ self.string().into_bytes_with_nul()
}
}