Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the pr, I thought JsValue
implemented Serialize
so I didn't realize this would be an issue. I am a bit uneasy about the method you introduced as it's specific to byte slices.
I think it would be better if we could provide something like a put_js_value
for any value the user would like to store that cannot be represented with ToRawKvValue
. So for the same result as your method we'd have something like:
let buffer = &[1, 2, 3, 4];
let typed_array = Uint8Array::new_with_length(buffer.len() as u32);
typed_array.copy_from(buffer);
kv.put_js_value("example", JsValue::from(typed_array))
.execute()
.await?;
You are right that the method is specific to byte slices and I understand that it sticks out a bit. But the alternative of passing in an arbitrary I think ideally there would be multiple different put methods for high-level Rust types (it would probably also make sense to support streams, for example) but of course I understand if you do not want to go ahead with such a change right now. Do you want me to go ahead and replace the |
You have a good point about a potential impl ToRawKvValue for [u8] {
fn raw_kv_value(&self) -> Result<JsValue, KvError> {
let typed_array = Uint8Array::new_with_length(self.len() as u32);
typed_array.copy_from(self);
Ok(typed_array.into())
}
} |
Are you sure the above solves the issue? This implements
I think it would be extremely nice if the API would support the other types (or rather their Rust equivalents) that Cloudflare accepts:
Are you sure that all values are stored as text on Cloudflare's end? The following snippet from the docs leads me to believe that binary values are supported and I haven't been able to find any information indicating the opposite:
|
You're right, I didn't think my reply through!
This image leads me to believe they are, but that could just be the dashboard.
Ah, I see. If you could just rename |
I will make a release with this and a few other bug fixes by the end of the week hopefully. |
This PR adds a method to put a slice of bytes into a KV store, which is not possible with the existing methods as a slice does not implement the necessary trait bounds.