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/render_layer.rs | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'rust/src/render_layer.rs') 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( +pub fn register_render_layer( name: S, render_layer: T, default_state: RenderLayerDefaultState, @@ -75,7 +75,7 @@ pub fn register_render_layer( }; 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(name: S) -> Option { - let name_raw = name.into_bytes_with_nul(); + pub fn render_layer_by_name(name: S) -> Option { + 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) } -- cgit v1.3.1