From 788a8b7091bbdde77817030e0836d7a7a786fd99 Mon Sep 17 00:00:00 2001 From: Mason Reed Date: Sun, 4 May 2025 19:47:55 -0400 Subject: [Rust] Simplify usage surrounding c strings `cstring.as_ref().as_ptr() as *const c_char` -> `cstring.as_ptr()` `cstring.as_ref().as_ptr() as *mut _` -> `cstring.as_ptr()` `cstring.as_ptr() as *const c_char` -> `cstring.as_ptr()` With a few fixes for cstrings that might be dropped prematurely. --- rust/src/project/folder.rs | 18 ++++-------------- 1 file changed, 4 insertions(+), 14 deletions(-) (limited to 'rust/src/project/folder.rs') diff --git a/rust/src/project/folder.rs b/rust/src/project/folder.rs index b8881ddc..80416197 100644 --- a/rust/src/project/folder.rs +++ b/rust/src/project/folder.rs @@ -8,7 +8,7 @@ use binaryninjacore_sys::{ BNProjectFolderGetName, BNProjectFolderGetParent, BNProjectFolderGetProject, BNProjectFolderSetDescription, BNProjectFolderSetName, BNProjectFolderSetParent, }; -use std::ffi::{c_char, c_void}; +use std::ffi::c_void; use std::fmt::Debug; use std::ptr::{null_mut, NonNull}; @@ -48,12 +48,7 @@ impl ProjectFolder { /// Set the name of this folder pub fn set_name(&self, value: S) -> bool { let value_raw = value.to_cstr(); - unsafe { - BNProjectFolderSetName( - self.handle.as_ptr(), - value_raw.as_ref().as_ptr() as *const c_char, - ) - } + unsafe { BNProjectFolderSetName(self.handle.as_ptr(), value_raw.as_ptr()) } } /// Get the description of this folder @@ -64,12 +59,7 @@ impl ProjectFolder { /// Set the description of this folder pub fn set_description(&self, value: S) -> bool { let value_raw = value.to_cstr(); - unsafe { - BNProjectFolderSetDescription( - self.handle.as_ptr(), - value_raw.as_ref().as_ptr() as *const c_char, - ) - } + unsafe { BNProjectFolderSetDescription(self.handle.as_ptr(), value_raw.as_ptr()) } } /// Get the folder that contains this folder @@ -107,7 +97,7 @@ impl ProjectFolder { let success = unsafe { BNProjectFolderExport( self.handle.as_ptr(), - dest_raw.as_ref().as_ptr() as *const c_char, + dest_raw.as_ptr(), &mut progress as *mut P as *mut c_void, Some(P::cb_progress_callback), ) -- cgit v1.3.1