sciter-sdk / rust-sciter

Rust bindings for Sciter
https://sciter.com
MIT License
806 stars 75 forks source link

Is this the best way to send a `Vec<u8>` of pixels to Sciter as image bytes? #85

Closed GirkovArpa closed 3 years ago

GirkovArpa commented 3 years ago

Briefly, here is what I'm doing which works:

use sciter_serde::{to_value};
use serde_bytes::Bytes;
let bytes: Vec<u8> = my_image_magick_function();
let output = to_value(&Bytes::new(&bytes));
done.call(None, &make_args!(output), None).unwrap()
function onDone(imageBytes) {
  $(img).value = Image.fromBytes(imageBytes);
}

I don't want to perform any unnecessary serialization step, so is there a better way?

pravic commented 3 years ago

Value::from(&bytes).

https://docs.rs/sciter-rs/0.5.53/sciter/value/struct.Value.html#trait-implementations

GirkovArpa commented 3 years ago

I get this error:

expected an Fn<(&[Value],)> closure, found Vec<u8>

GirkovArpa commented 3 years ago

Solved:

Value::from(&bytes[..])