pub struct Captures(/* private fields */);
Expand description
Wrapper for Box<dyn NativeObject + Clone>
that allows passing additional
captures through a Copy
closure.
Any type implementing Trace + Any + Debug + Clone
can be used as a capture context, so you can pass e.g. a String,
a tuple or even a full struct.
You can downcast to any type and handle the fail case as you like
with downcast_ref
and downcast_mut
, or you can use try_downcast_ref
and try_downcast_mut
to automatically throw a TypeError
if the downcast
fails.
Implementations§
Source§impl Captures
impl Captures
Sourcepub fn downcast_ref<T>(&self) -> Option<&T>where
T: NativeObject + Clone,
pub fn downcast_ref<T>(&self) -> Option<&T>where
T: NativeObject + Clone,
Downcasts Captures
to the specified type, returning a reference to the
downcasted type if successful or None
otherwise.
Sourcepub fn downcast_mut<T>(&mut self) -> Option<&mut T>where
T: NativeObject + Clone,
pub fn downcast_mut<T>(&mut self) -> Option<&mut T>where
T: NativeObject + Clone,
Mutably downcasts Captures
to the specified type, returning a
mutable reference to the downcasted type if successful or None
otherwise.
Sourcepub fn try_downcast_ref<T>(&self, context: &mut Context) -> JsResult<&T>where
T: NativeObject + Clone,
pub fn try_downcast_ref<T>(&self, context: &mut Context) -> JsResult<&T>where
T: NativeObject + Clone,
Downcasts Captures
to the specified type, returning a reference to the
downcasted type if successful or a TypeError
otherwise.
Sourcepub fn try_downcast_mut<T>(&mut self, context: &mut Context) -> JsResult<&mut T>where
T: NativeObject + Clone,
pub fn try_downcast_mut<T>(&mut self, context: &mut Context) -> JsResult<&mut T>where
T: NativeObject + Clone,
Downcasts Captures
to the specified type, returning a reference to the
downcasted type if successful or a TypeError
otherwise.