Skip to main content

TryFromJsRefMut

Trait TryFromJsRefMut 

Source
pub trait TryFromJsRefMut<'cx>
where Self: Sealed + Sized,
{ type Guard: DerefMut<Target = Self>; type Error: TryIntoJs<'cx>; // Required method fn try_from_js_ref_mut( cx: &mut Cx<'cx>, v: Handle<'cx, JsValue>, ) -> NeonResult<Result<Self::Guard, Self::Error>>; // Provided method fn from_js_ref_mut( cx: &mut Cx<'cx>, v: Handle<'cx, JsValue>, ) -> NeonResult<Self::Guard> { ... } }
Expand description

Extract a mutable borrowed reference to Rust data from a JavaScript value

This trait is similar to TryFromJsRef, but returns a guard that allows mutable access. This is useful for passing class instances by mutable reference in method calls.

§Example

// In a class method, accept another instance by mutable reference
pub fn swap_coordinates(&mut self, other: &mut Point) {
    std::mem::swap(&mut self.x, &mut other.x);
    std::mem::swap(&mut self.y, &mut other.y);
}

The macro will automatically use TryFromJsRefMut when it sees &mut T parameters.

Required Associated Types§

Source

type Guard: DerefMut<Target = Self>

A guard type that dereferences to &mut Self and keeps the mutable borrow alive

Source

type Error: TryIntoJs<'cx>

The error type returned when extraction fails

Required Methods§

Source

fn try_from_js_ref_mut( cx: &mut Cx<'cx>, v: Handle<'cx, JsValue>, ) -> NeonResult<Result<Self::Guard, Self::Error>>

Extract a mutable borrowed reference from a JavaScript value

Provided Methods§

Source

fn from_js_ref_mut( cx: &mut Cx<'cx>, v: Handle<'cx, JsValue>, ) -> NeonResult<Self::Guard>

Same as TryFromJsRefMut::try_from_js_ref_mut, but all errors are converted to JavaScript exceptions

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§