summaryrefslogtreecommitdiff
path: root/rust/src/websocket/client.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/websocket/client.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/websocket/client.rs')
-rw-r--r--rust/src/websocket/client.rs25
1 files changed, 9 insertions, 16 deletions
diff --git a/rust/src/websocket/client.rs b/rust/src/websocket/client.rs
index aa69c381..fc56dc0b 100644
--- a/rust/src/websocket/client.rs
+++ b/rust/src/websocket/client.rs
@@ -18,11 +18,9 @@ pub trait WebsocketClient: Sync + Send {
/// Called to construct this client object with the given core object.
fn from_core(core: Ref<CoreWebsocketClient>) -> Self;
- fn connect<I, K, V>(&self, host: &str, headers: I) -> bool
+ fn connect<I>(&self, host: &str, headers: I) -> bool
where
- I: IntoIterator<Item = (K, V)>,
- K: IntoCStr,
- V: IntoCStr;
+ I: IntoIterator<Item = (String, String)>;
fn write(&self, data: &[u8]) -> bool;
@@ -69,20 +67,13 @@ impl CoreWebsocketClient {
/// * `host` - Full url with scheme, domain, optionally port, and path
/// * `headers` - HTTP header keys and values
/// * `callback` - Callbacks for various websocket events
- pub fn initialize_connection<I, K, V, C>(
- &self,
- host: &str,
- headers: I,
- callbacks: &mut C,
- ) -> bool
+ pub fn initialize_connection<I, C>(&self, host: &str, headers: I, callbacks: &mut C) -> bool
where
- I: IntoIterator<Item = (K, V)>,
- K: IntoCStr,
- V: IntoCStr,
+ I: IntoIterator<Item = (String, String)>,
C: WebsocketClientCallback,
{
let url = host.to_cstr();
- let (header_keys, header_values): (Vec<K::Result>, Vec<V::Result>) = headers
+ let (header_keys, header_values): (Vec<_>, Vec<_>) = headers
.into_iter()
.map(|(k, v)| (k.to_cstr(), v.to_cstr()))
.unzip();
@@ -187,8 +178,10 @@ pub(crate) unsafe extern "C" fn cb_connect<W: WebsocketClient>(
let header_count = usize::try_from(header_count).unwrap();
let header_keys = core::slice::from_raw_parts(header_keys as *const BnString, header_count);
let header_values = core::slice::from_raw_parts(header_values as *const BnString, header_count);
- let header_keys_str = header_keys.iter().map(|s| s.to_string_lossy());
- let header_values_str = header_values.iter().map(|s| s.to_string_lossy());
+ let header_keys_str = header_keys.iter().map(|s| s.to_string_lossy().to_string());
+ let header_values_str = header_values
+ .iter()
+ .map(|s| s.to_string_lossy().to_string());
let header = header_keys_str.zip(header_values_str);
ctxt.connect(&host.to_string_lossy(), header)
}