diff options
| author | Mason Reed <mason@vector35.com> | 2025-05-04 19:10:56 -0400 |
|---|---|---|
| committer | Mason Reed <35282038+emesare@users.noreply.github.com> | 2025-05-12 17:45:24 -0400 |
| commit | a826c589dfc10c542deba7ca3343a462e02d6bde (patch) | |
| tree | f116254bef39f787268bbecc5eac19da310db9ce /rust/src/custom_binary_view.rs | |
| parent | 28b3c4044af06fdc32c9c85bf8381b5058306427 (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/custom_binary_view.rs')
| -rw-r--r-- | rust/src/custom_binary_view.rs | 10 |
1 files changed, 5 insertions, 5 deletions
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<S, T, F>(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<N: BnStrCompatible>(name: N) -> Result<Self> { - let bytes = name.into_bytes_with_nul(); + pub fn by_name<N: AsCStr>(name: N) -> Result<Self> { + 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) }), |
