summaryrefslogtreecommitdiff
path: root/rust/src/collaboration.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/collaboration.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/collaboration.rs')
-rw-r--r--rust/src/collaboration.rs21
1 files changed, 9 insertions, 12 deletions
diff --git a/rust/src/collaboration.rs b/rust/src/collaboration.rs
index 9a97a0e8..0a17d94c 100644
--- a/rust/src/collaboration.rs
+++ b/rust/src/collaboration.rs
@@ -73,21 +73,21 @@ pub fn known_remotes() -> Array<Remote> {
}
/// Get Remote by unique `id`
-pub fn get_remote_by_id<S: IntoCStr>(id: S) -> Option<Ref<Remote>> {
+pub fn get_remote_by_id(id: &str) -> Option<Ref<Remote>> {
let id = id.to_cstr();
let value = unsafe { BNCollaborationGetRemoteById(id.as_ptr()) };
NonNull::new(value).map(|h| unsafe { Remote::ref_from_raw(h) })
}
/// Get Remote by `address`
-pub fn get_remote_by_address<S: IntoCStr>(address: S) -> Option<Ref<Remote>> {
+pub fn get_remote_by_address(address: &str) -> Option<Ref<Remote>> {
let address = address.to_cstr();
let value = unsafe { BNCollaborationGetRemoteByAddress(address.as_ptr()) };
NonNull::new(value).map(|h| unsafe { Remote::ref_from_raw(h) })
}
/// Get Remote by `name`
-pub fn get_remote_by_name<S: IntoCStr>(name: S) -> Option<Ref<Remote>> {
+pub fn get_remote_by_name(name: &str) -> Option<Ref<Remote>> {
let name = name.to_cstr();
let value = unsafe { BNCollaborationGetRemoteByName(name.as_ptr()) };
NonNull::new(value).map(|h| unsafe { Remote::ref_from_raw(h) })
@@ -103,15 +103,12 @@ pub fn save_remotes() {
unsafe { BNCollaborationSaveRemotes() }
}
-pub fn store_data_in_keychain<K, I, DK, DV>(key: K, data: I) -> bool
+pub fn store_data_in_keychain<I>(key: &str, data: I) -> bool
where
- K: IntoCStr,
- I: IntoIterator<Item = (DK, DV)>,
- DK: IntoCStr,
- DV: IntoCStr,
+ I: IntoIterator<Item = (String, String)>,
{
let key = key.to_cstr();
- let (data_keys, data_values): (Vec<DK::Result>, Vec<DV::Result>) = data
+ let (data_keys, data_values): (Vec<_>, Vec<_>) = data
.into_iter()
.map(|(k, v)| (k.to_cstr(), v.to_cstr()))
.unzip();
@@ -127,12 +124,12 @@ where
}
}
-pub fn has_data_in_keychain<K: IntoCStr>(key: K) -> bool {
+pub fn has_data_in_keychain(key: &str) -> bool {
let key = key.to_cstr();
unsafe { BNCollaborationHasDataInKeychain(key.as_ptr()) }
}
-pub fn get_data_from_keychain<K: IntoCStr>(key: K) -> Option<(Array<BnString>, Array<BnString>)> {
+pub fn get_data_from_keychain(key: &str) -> Option<(Array<BnString>, Array<BnString>)> {
let key = key.to_cstr();
let mut keys = std::ptr::null_mut();
let mut values = std::ptr::null_mut();
@@ -142,7 +139,7 @@ pub fn get_data_from_keychain<K: IntoCStr>(key: K) -> Option<(Array<BnString>, A
keys.zip(values)
}
-pub fn delete_data_from_keychain<K: IntoCStr>(key: K) -> bool {
+pub fn delete_data_from_keychain(key: &str) -> bool {
let key = key.to_cstr();
unsafe { BNCollaborationDeleteDataFromKeychain(key.as_ptr()) }
}