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/custom_binary_view.rs | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'rust/src/custom_binary_view.rs') diff --git a/rust/src/custom_binary_view.rs b/rust/src/custom_binary_view.rs index de841a26..adcde09d 100644 --- a/rust/src/custom_binary_view.rs +++ b/rust/src/custom_binary_view.rs @@ -42,7 +42,7 @@ use crate::Endianness; /// implementation of the `CustomBinaryViewType` must return. pub fn register_view_type(name: S, long_name: S, constructor: F) -> &'static T where - S: BnStrCompatible, + S: AsCStr, T: CustomBinaryViewType, F: FnOnce(BinaryViewType) -> T, { @@ -149,10 +149,10 @@ where }) } - let name = name.into_bytes_with_nul(); + let name = name.to_cstr(); let name_ptr = name.as_ref().as_ptr() as *mut _; - let long_name = long_name.into_bytes_with_nul(); + let long_name = long_name.to_cstr(); let long_name_ptr = long_name.as_ref().as_ptr() as *mut _; let ctxt = Box::leak(Box::new(MaybeUninit::zeroed())); @@ -360,8 +360,8 @@ impl BinaryViewType { } /// Looks up a BinaryViewType by its short name - pub fn by_name(name: N) -> Result { - let bytes = name.into_bytes_with_nul(); + pub fn by_name(name: N) -> Result { + let bytes = name.to_cstr(); let handle = unsafe { BNGetBinaryViewTypeByName(bytes.as_ref().as_ptr() as *const _) }; match handle.is_null() { false => Ok(unsafe { BinaryViewType::from_raw(handle) }), -- cgit v1.3.1