From a826c589dfc10c542deba7ca3343a462e02d6bde Mon Sep 17 00:00:00 2001 From: Mason Reed Date: Sun, 4 May 2025 19:10:56 -0400 Subject: [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 --- rust/src/component.rs | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) (limited to 'rust/src/component.rs') 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(&self, name: S) { - let name = name.into_bytes_with_nul(); + pub fn set_name(&self, name: S) { + let name = name.to_cstr(); unsafe { BNComponentSetName( self.handle.as_ptr(), -- cgit v1.3.1