summaryrefslogtreecommitdiff
path: root/rust/src/component.rs
diff options
context:
space:
mode:
authorMason Reed <mason@vector35.com>2025-05-04 19:10:56 -0400
committerMason Reed <35282038+emesare@users.noreply.github.com>2025-05-12 17:45:24 -0400
commita826c589dfc10c542deba7ca3343a462e02d6bde (patch)
treef116254bef39f787268bbecc5eac19da310db9ce /rust/src/component.rs
parent28b3c4044af06fdc32c9c85bf8381b5058306427 (diff)
[Rust] Simplify `BnStrCompatible` trait
Followup to https://github.com/Vector35/binaryninja-api/pull/5897/ This simplifies usage of the trait in user code, should just be able to `to_cstr` to get the cstr repr and then call `as_ptr`. Co-authored-by: Michael Krasnitski <michael.krasnitski@gmail.com>
Diffstat (limited to 'rust/src/component.rs')
-rw-r--r--rust/src/component.rs14
1 files changed, 7 insertions, 7 deletions
diff --git a/rust/src/component.rs b/rust/src/component.rs
index 72441c52..5fe44b64 100644
--- a/rust/src/component.rs
+++ b/rust/src/component.rs
@@ -1,7 +1,7 @@
use crate::binary_view::{BinaryView, BinaryViewExt};
use crate::function::Function;
use crate::rc::{Array, CoreArrayProvider, CoreArrayProviderInner, Guard, Ref, RefCountable};
-use crate::string::{BnStrCompatible, BnString};
+use crate::string::{AsCStr, BnString};
use crate::types::ComponentReferencedType;
use std::ffi::c_char;
use std::fmt::Debug;
@@ -39,20 +39,20 @@ impl ComponentBuilder {
let result = match (&self.parent, &self.name) {
(None, None) => unsafe { BNCreateComponent(self.view.handle) },
(None, Some(name)) => {
- let name_raw = name.into_bytes_with_nul();
+ let name_raw = name.to_cstr();
unsafe {
BNCreateComponentWithName(self.view.handle, name_raw.as_ptr() as *mut c_char)
}
}
(Some(guid), None) => {
- let guid_raw = guid.into_bytes_with_nul();
+ let guid_raw = guid.to_cstr();
unsafe {
BNCreateComponentWithParent(self.view.handle, guid_raw.as_ptr() as *mut c_char)
}
}
(Some(guid), Some(name)) => {
- let guid_raw = guid.into_bytes_with_nul();
- let name_raw = name.into_bytes_with_nul();
+ let guid_raw = guid.to_cstr();
+ let name_raw = name.to_cstr();
unsafe {
BNCreateComponentWithParentAndName(
self.view.handle,
@@ -164,8 +164,8 @@ impl Component {
unsafe { BnString::into_string(result) }
}
- pub fn set_name<S: BnStrCompatible>(&self, name: S) {
- let name = name.into_bytes_with_nul();
+ pub fn set_name<S: AsCStr>(&self, name: S) {
+ let name = name.to_cstr();
unsafe {
BNComponentSetName(
self.handle.as_ptr(),