Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to turn Rust Image buffer Vec<u8> to JsBuffer? #980

Closed
WeismannS opened this issue Apr 7, 2023 · 2 comments
Closed

How to turn Rust Image buffer Vec<u8> to JsBuffer? #980

WeismannS opened this issue Apr 7, 2023 · 2 comments

Comments

@WeismannS
Copy link

Code snipper:
I'm using the image and imageproc crates

let buffer =  image3.into_raw();
 Ok(cx.buffer(buffer as usize)?)``` obviously doesn't work but i don't what to do
@kjvalencik
Copy link
Member

https://docs.rs/neon/1.0.0-alpha.2/neon/types/buffer/trait.TypedArray.html#tymethod.from_slice

use neon::types::JsUint8Array;

// Replace with the real data in a `Vec<u8>`
let data: Vec<u8> = vec![1, 2, 3, 4];

JsUint8Array::from_slice(&data)

Note, as of writing this is only available in the 1.0 pre-release (1.0.0-alpha.2). In 0.10, there is a bit more boilerplate.

let mut buf = cx.array_buffer(data.len());

buf.as_mut_slice(&mut cx).copy_from_slice(&data);

Ok(buf)

@kjvalencik
Copy link
Member

As linked above, that method is on the TypedArray trait which needs to be in scope to call it.

use neon::types::buffer::TypedArray;

I hope this helps. I'm going to close this issue since it's more of a support request than an issue with Neon. Cheers!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants