summaryrefslogtreecommitdiff
path: root/rust/src/download_provider.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/download_provider.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/download_provider.rs')
-rw-r--r--rust/src/download_provider.rs28
1 files changed, 13 insertions, 15 deletions
diff --git a/rust/src/download_provider.rs b/rust/src/download_provider.rs
index 4b7b3c0c..f9e21e64 100644
--- a/rust/src/download_provider.rs
+++ b/rust/src/download_provider.rs
@@ -1,6 +1,6 @@
use crate::rc::{Array, CoreArrayProvider, CoreArrayProviderInner, Guard, Ref, RefCountable};
use crate::settings::Settings;
-use crate::string::{BnStrCompatible, BnString};
+use crate::string::{AsCStr, BnString};
use binaryninjacore_sys::*;
use std::collections::HashMap;
use std::ffi::{c_void, CStr};
@@ -13,11 +13,9 @@ pub struct DownloadProvider {
}
impl DownloadProvider {
- pub fn get<S: BnStrCompatible>(name: S) -> Option<DownloadProvider> {
+ pub fn get<S: AsCStr>(name: S) -> Option<DownloadProvider> {
let result = unsafe {
- BNGetDownloadProviderByName(
- name.into_bytes_with_nul().as_ref().as_ptr() as *const c_char
- )
+ BNGetDownloadProviderByName(name.to_cstr().as_ref().as_ptr() as *const c_char)
};
if result.is_null() {
return None;
@@ -134,7 +132,7 @@ impl DownloadInstance {
}
}
- pub fn perform_request<S: BnStrCompatible>(
+ pub fn perform_request<S: AsCStr>(
&mut self,
url: S,
callbacks: DownloadInstanceOutputCallbacks,
@@ -150,7 +148,7 @@ impl DownloadInstance {
let result = unsafe {
BNPerformDownloadRequest(
self.handle,
- url.into_bytes_with_nul().as_ref().as_ptr() as *const c_char,
+ url.to_cstr().as_ref().as_ptr() as *const c_char,
&mut cbs as *mut BNDownloadInstanceOutputCallbacks,
)
};
@@ -204,10 +202,10 @@ impl DownloadInstance {
}
pub fn perform_custom_request<
- M: BnStrCompatible,
- U: BnStrCompatible,
- HK: BnStrCompatible,
- HV: BnStrCompatible,
+ M: AsCStr,
+ U: AsCStr,
+ HK: AsCStr,
+ HV: AsCStr,
I: IntoIterator<Item = (HK, HV)>,
>(
&mut self,
@@ -219,8 +217,8 @@ impl DownloadInstance {
let mut header_keys = vec![];
let mut header_values = vec![];
for (key, value) in headers {
- header_keys.push(key.into_bytes_with_nul());
- header_values.push(value.into_bytes_with_nul());
+ header_keys.push(key.to_cstr());
+ header_values.push(value.to_cstr());
}
let mut header_key_ptrs = vec![];
@@ -246,8 +244,8 @@ impl DownloadInstance {
let result = unsafe {
BNPerformCustomRequest(
self.handle,
- method.into_bytes_with_nul().as_ref().as_ptr() as *const c_char,
- url.into_bytes_with_nul().as_ref().as_ptr() as *const c_char,
+ method.to_cstr().as_ref().as_ptr() as *const c_char,
+ url.to_cstr().as_ref().as_ptr() as *const c_char,
header_key_ptrs.len() as u64,
header_key_ptrs.as_ptr(),
header_value_ptrs.as_ptr(),