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§
Required Methods§
Sourcefn try_from_js_ref_mut(
cx: &mut Cx<'cx>,
v: Handle<'cx, JsValue>,
) -> NeonResult<Result<Self::Guard, Self::Error>>
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§
Sourcefn from_js_ref_mut(
cx: &mut Cx<'cx>,
v: Handle<'cx, JsValue>,
) -> NeonResult<Self::Guard>
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", so this trait is not object safe.