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/render_layer.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/render_layer.rs')
| -rw-r--r-- | rust/src/render_layer.rs | 10 |
1 files changed, 5 insertions, 5 deletions
diff --git a/rust/src/render_layer.rs b/rust/src/render_layer.rs index 80ecc639..175ee167 100644 --- a/rust/src/render_layer.rs +++ b/rust/src/render_layer.rs @@ -6,7 +6,7 @@ use crate::flowgraph::FlowGraph; use crate::function::{Function, NativeBlock}; use crate::linear_view::{LinearDisassemblyLine, LinearDisassemblyLineType, LinearViewObject}; use crate::rc::{Array, CoreArrayProvider, CoreArrayProviderInner}; -use crate::string::BnStrCompatible; +use crate::string::AsCStr; use binaryninjacore_sys::*; use std::ffi::{c_char, c_void}; use std::ptr::NonNull; @@ -61,7 +61,7 @@ impl Default for RenderLayerDefaultState { } /// Register a [`RenderLayer`] with the API. -pub fn register_render_layer<S: BnStrCompatible, T: RenderLayer>( +pub fn register_render_layer<S: AsCStr, T: RenderLayer>( name: S, render_layer: T, default_state: RenderLayerDefaultState, @@ -75,7 +75,7 @@ pub fn register_render_layer<S: BnStrCompatible, T: RenderLayer>( }; let result = unsafe { BNRegisterRenderLayer( - name.into_bytes_with_nul().as_ref().as_ptr() as *const _, + name.to_cstr().as_ref().as_ptr() as *const _, &mut callback, default_state.into(), ) @@ -303,8 +303,8 @@ impl CoreRenderLayer { unsafe { Array::new(result, count, ()) } } - pub fn render_layer_by_name<S: BnStrCompatible>(name: S) -> Option<CoreRenderLayer> { - let name_raw = name.into_bytes_with_nul(); + pub fn render_layer_by_name<S: AsCStr>(name: S) -> Option<CoreRenderLayer> { + let name_raw = name.to_cstr(); let result = unsafe { BNGetRenderLayerByName(name_raw.as_ref().as_ptr() as *const c_char) }; NonNull::new(result).map(Self::from_raw) } |
