summaryrefslogtreecommitdiff
path: root/rust/src/project
diff options
context:
space:
mode:
authorMason Reed <mason@vector35.com>2025-05-04 19:47:55 -0400
committerMason Reed <35282038+emesare@users.noreply.github.com>2025-05-12 17:45:24 -0400
commit788a8b7091bbdde77817030e0836d7a7a786fd99 (patch)
tree40e8f8d3c870788259a5acb5d14995cdc1656979 /rust/src/project
parenta826c589dfc10c542deba7ca3343a462e02d6bde (diff)
[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.
Diffstat (limited to 'rust/src/project')
-rw-r--r--rust/src/project/file.rs22
-rw-r--r--rust/src/project/folder.rs18
2 files changed, 7 insertions, 33 deletions
diff --git a/rust/src/project/file.rs b/rust/src/project/file.rs
index d1724ab0..bc486ed9 100644
--- a/rust/src/project/file.rs
+++ b/rust/src/project/file.rs
@@ -8,7 +8,6 @@ use binaryninjacore_sys::{
BNProjectFileGetPathOnDisk, BNProjectFileGetProject, BNProjectFileSetDescription,
BNProjectFileSetFolder, BNProjectFileSetName,
};
-use std::ffi::c_char;
use std::fmt::Debug;
use std::ptr::{null_mut, NonNull};
use std::time::SystemTime;
@@ -59,12 +58,7 @@ impl ProjectFile {
/// Set the name of this file
pub fn set_name<S: AsCStr>(&self, value: S) -> bool {
let value_raw = value.to_cstr();
- unsafe {
- BNProjectFileSetName(
- self.handle.as_ptr(),
- value_raw.as_ref().as_ptr() as *const c_char,
- )
- }
+ unsafe { BNProjectFileSetName(self.handle.as_ptr(), value_raw.as_ptr()) }
}
/// Get the description of this file
@@ -75,12 +69,7 @@ impl ProjectFile {
/// Set the description of this file
pub fn set_description<S: AsCStr>(&self, value: S) -> bool {
let value_raw = value.to_cstr();
- unsafe {
- BNProjectFileSetDescription(
- self.handle.as_ptr(),
- value_raw.as_ref().as_ptr() as *const c_char,
- )
- }
+ unsafe { BNProjectFileSetDescription(self.handle.as_ptr(), value_raw.as_ptr()) }
}
/// Get the file creation time
@@ -106,12 +95,7 @@ impl ProjectFile {
/// * `dest` - Destination path for the exported contents
pub fn export<S: AsCStr>(&self, dest: S) -> bool {
let dest_raw = dest.to_cstr();
- unsafe {
- BNProjectFileExport(
- self.handle.as_ptr(),
- dest_raw.as_ref().as_ptr() as *const c_char,
- )
- }
+ unsafe { BNProjectFileExport(self.handle.as_ptr(), dest_raw.as_ptr()) }
}
}
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<S: AsCStr>(&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<S: AsCStr>(&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),
)