summaryrefslogtreecommitdiff
path: root/rust/src/command.rs
diff options
context:
space:
mode:
authorMason Reed <mason@vector35.com>2025-05-04 19:10:56 -0400
committerMason Reed <35282038+emesare@users.noreply.github.com>2025-05-12 17:45:24 -0400
commita826c589dfc10c542deba7ca3343a462e02d6bde (patch)
treef116254bef39f787268bbecc5eac19da310db9ce /rust/src/command.rs
parent28b3c4044af06fdc32c9c85bf8381b5058306427 (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/command.rs')
-rw-r--r--rust/src/command.rs26
1 files changed, 13 insertions, 13 deletions
diff --git a/rust/src/command.rs b/rust/src/command.rs
index 48a91164..0297d6cf 100644
--- a/rust/src/command.rs
+++ b/rust/src/command.rs
@@ -42,7 +42,7 @@ use std::os::raw::c_void;
use crate::binary_view::BinaryView;
use crate::function::Function;
-use crate::string::BnStrCompatible;
+use crate::string::AsCStr;
/// The trait required for generic commands. See [register_command] for example usage.
pub trait Command: 'static + Sync {
@@ -95,7 +95,7 @@ where
/// ```
pub fn register_command<S, C>(name: S, desc: S, command: C)
where
- S: BnStrCompatible,
+ S: AsCStr,
C: Command,
{
extern "C" fn cb_action<C>(ctxt: *mut c_void, view: *mut BNBinaryView)
@@ -126,8 +126,8 @@ where
})
}
- let name = name.into_bytes_with_nul();
- let desc = desc.into_bytes_with_nul();
+ let name = name.to_cstr();
+ let desc = desc.to_cstr();
let name_ptr = name.as_ref().as_ptr() as *mut _;
let desc_ptr = desc.as_ref().as_ptr() as *mut _;
@@ -196,7 +196,7 @@ where
/// ```
pub fn register_command_for_address<S, C>(name: S, desc: S, command: C)
where
- S: BnStrCompatible,
+ S: AsCStr,
C: AddressCommand,
{
extern "C" fn cb_action<C>(ctxt: *mut c_void, view: *mut BNBinaryView, addr: u64)
@@ -227,8 +227,8 @@ where
})
}
- let name = name.into_bytes_with_nul();
- let desc = desc.into_bytes_with_nul();
+ let name = name.to_cstr();
+ let desc = desc.to_cstr();
let name_ptr = name.as_ref().as_ptr() as *mut _;
let desc_ptr = desc.as_ref().as_ptr() as *mut _;
@@ -298,7 +298,7 @@ where
/// ```
pub fn register_command_for_range<S, C>(name: S, desc: S, command: C)
where
- S: BnStrCompatible,
+ S: AsCStr,
C: RangeCommand,
{
extern "C" fn cb_action<C>(ctxt: *mut c_void, view: *mut BNBinaryView, addr: u64, len: u64)
@@ -334,8 +334,8 @@ where
})
}
- let name = name.into_bytes_with_nul();
- let desc = desc.into_bytes_with_nul();
+ let name = name.to_cstr();
+ let desc = desc.to_cstr();
let name_ptr = name.as_ref().as_ptr() as *mut _;
let desc_ptr = desc.as_ref().as_ptr() as *mut _;
@@ -405,7 +405,7 @@ where
/// ```
pub fn register_command_for_function<S, C>(name: S, desc: S, command: C)
where
- S: BnStrCompatible,
+ S: AsCStr,
C: FunctionCommand,
{
extern "C" fn cb_action<C>(ctxt: *mut c_void, view: *mut BNBinaryView, func: *mut BNFunction)
@@ -446,8 +446,8 @@ where
})
}
- let name = name.into_bytes_with_nul();
- let desc = desc.into_bytes_with_nul();
+ let name = name.to_cstr();
+ let desc = desc.to_cstr();
let name_ptr = name.as_ref().as_ptr() as *mut _;
let desc_ptr = desc.as_ref().as_ptr() as *mut _;