pub struct SafeArrayBuffer { /* private fields */ }
Expand description
Rust representation of Nodejs ArrayBuffer In regular cases can be used ArrayBuffer and it will be more effective. But in the case of usage node_bindgen in electron context, ArrayBuffer will not work because of restrictions from electron side. SafeArrayBuffer can be used as an effective workaround. Theoretically, usage of SafeArrayBuffer might give a very small performance degradation compared to ArrayBuffer, but it can be ignored in most cases.
§Examples
use node_bindgen::derive::node_bindgen;
use node_bindgen::core::{buffer::JSArrayBuffer, safebuffer::{SafeArrayBuffer}};
#[node_bindgen]
fn msg_from_js(data: JSArrayBuffer) -> Result<String, NjError> {
let message = String::from_utf8(data.to_vec())?;
Ok(format!("reply {}", message))
}
#[node_bindgen]
fn msg_to_js() -> Result<SafeArrayBuffer, NjError> {
let message = String::from("Hello from Rust!");
Ok(SafeArrayBuffer::new(message.to_vec()))
}
Implementations§
Source§impl SafeArrayBuffer
impl SafeArrayBuffer
pub fn new(data: Vec<u8>) -> SafeArrayBuffer
Trait Implementations§
Source§impl Debug for SafeArrayBuffer
impl Debug for SafeArrayBuffer
Auto Trait Implementations§
impl Freeze for SafeArrayBuffer
impl RefUnwindSafe for SafeArrayBuffer
impl Send for SafeArrayBuffer
impl Sync for SafeArrayBuffer
impl Unpin for SafeArrayBuffer
impl UnwindSafe for SafeArrayBuffer
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more