From 2f214f6c9935e8ce8df4732cde44a540a003258c Mon Sep 17 00:00:00 2001 From: Mason Reed Date: Wed, 7 May 2025 19:22:21 -0400 Subject: [Rust] Reduce usage of `IntoCStr` in function signatures This is being done to reduce complexity in function signatures, specifically many of the strings we are passing ultimately should be new types themselves instead of "just strings", things such as type ids. Another place which was confusing was dealing with filesystem related APIs, this commit turns most of those params into a stricter `Path` type. This is bringing the rust api more inline with both python and C++, where the wrapper eagerly converts the string into the languages standard string type. Special consideration must be made for symbols or other possible non utf-8 objects. This commit will be followed up with one that adds the `IntoCStr` bound on API's we want to keep as invalid utf-8 so we can for example, get section by name on a section with invalid utf-8. --- rust/src/command.rs | 21 ++++----------------- 1 file changed, 4 insertions(+), 17 deletions(-) (limited to 'rust/src/command.rs') diff --git a/rust/src/command.rs b/rust/src/command.rs index 099eafa8..46f43bbd 100644 --- a/rust/src/command.rs +++ b/rust/src/command.rs @@ -93,11 +93,7 @@ where /// true /// } /// ``` -pub fn register_command(name: S, desc: S, command: C) -where - S: IntoCStr, - C: Command, -{ +pub fn register_command(name: &str, desc: &str, command: C) { extern "C" fn cb_action(ctxt: *mut c_void, view: *mut BNBinaryView) where C: Command, @@ -194,11 +190,7 @@ where /// true /// } /// ``` -pub fn register_command_for_address(name: S, desc: S, command: C) -where - S: IntoCStr, - C: AddressCommand, -{ +pub fn register_command_for_address(name: &str, desc: &str, command: C) { extern "C" fn cb_action(ctxt: *mut c_void, view: *mut BNBinaryView, addr: u64) where C: AddressCommand, @@ -296,9 +288,8 @@ where /// true /// } /// ``` -pub fn register_command_for_range(name: S, desc: S, command: C) +pub fn register_command_for_range(name: &str, desc: &str, command: C) where - S: IntoCStr, C: RangeCommand, { extern "C" fn cb_action(ctxt: *mut c_void, view: *mut BNBinaryView, addr: u64, len: u64) @@ -403,11 +394,7 @@ where /// true /// } /// ``` -pub fn register_command_for_function(name: S, desc: S, command: C) -where - S: IntoCStr, - C: FunctionCommand, -{ +pub fn register_command_for_function(name: &str, desc: &str, command: C) { extern "C" fn cb_action(ctxt: *mut c_void, view: *mut BNBinaryView, func: *mut BNFunction) where C: FunctionCommand, -- cgit v1.3.1