summaryrefslogtreecommitdiff
path: root/rust/src/download_provider.rs
diff options
context:
space:
mode:
authorMason Reed <mason@vector35.com>2025-05-07 19:22:21 -0400
committerMason Reed <35282038+emesare@users.noreply.github.com>2025-05-12 17:45:24 -0400
commit2f214f6c9935e8ce8df4732cde44a540a003258c (patch)
tree6fe319433ef0d2ad75fcc58a50eaa632bb627ec9 /rust/src/download_provider.rs
parentb4cf0be8816182c9efca037e27e9439482f8bf36 (diff)
[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.
Diffstat (limited to 'rust/src/download_provider.rs')
-rw-r--r--rust/src/download_provider.rs25
1 files changed, 11 insertions, 14 deletions
diff --git a/rust/src/download_provider.rs b/rust/src/download_provider.rs
index e74274f4..9fd803a7 100644
--- a/rust/src/download_provider.rs
+++ b/rust/src/download_provider.rs
@@ -13,7 +13,7 @@ pub struct DownloadProvider {
}
impl DownloadProvider {
- pub fn get<S: IntoCStr>(name: S) -> Option<DownloadProvider> {
+ pub fn get(name: &str) -> Option<DownloadProvider> {
let name = name.to_cstr();
let result = unsafe { BNGetDownloadProviderByName(name.as_ptr()) };
if result.is_null() {
@@ -37,7 +37,7 @@ impl DownloadProvider {
pub fn try_default() -> Result<DownloadProvider, ()> {
let s = Settings::new();
let dp_name = s.get_string("network.downloadProviderName");
- Self::get(dp_name).ok_or(())
+ Self::get(&dp_name).ok_or(())
}
pub(crate) fn from_raw(handle: *mut BNDownloadProvider) -> DownloadProvider {
@@ -131,9 +131,9 @@ impl DownloadInstance {
}
}
- pub fn perform_request<S: IntoCStr>(
+ pub fn perform_request(
&mut self,
- url: S,
+ url: &str,
callbacks: DownloadInstanceOutputCallbacks,
) -> Result<(), String> {
let callbacks = Box::into_raw(Box::new(callbacks));
@@ -201,19 +201,16 @@ impl DownloadInstance {
}
}
- pub fn perform_custom_request<
- M: IntoCStr,
- U: IntoCStr,
- HK: IntoCStr,
- HV: IntoCStr,
- I: Iterator<Item = (HK, HV)>,
- >(
+ pub fn perform_custom_request<I>(
&mut self,
- method: M,
- url: U,
+ method: &str,
+ url: &str,
headers: I,
callbacks: DownloadInstanceInputOutputCallbacks,
- ) -> Result<DownloadResponse, String> {
+ ) -> Result<DownloadResponse, String>
+ where
+ I: IntoIterator<Item = (String, String)>,
+ {
let mut header_keys = vec![];
let mut header_values = vec![];
for (key, value) in headers {