Struct lignin::callback_registry::CallbackRef [−][src]
pub struct CallbackRef<S, C> where
S: ThreadSafety,
C: CallbackSignature, { /* fields omitted */ }
Vdom
A callback reference linked to a CallbackRegistration
.
Implementations
impl<S: ThreadSafety, C> CallbackRef<S, C> where
C: CallbackSignature,
[src]
C: CallbackSignature,
#[must_use]pub fn deanonymize(self) -> Self
[src]
Call of .deanonymize()
on named type.
When called on an opaque type, deanonymizes it into the underlying named type.
Both AutoSafe
and Deanonymize
must be in scope and the method must be called without qualification for this to work.
Calling this method on a named type returns the value and type unchanged and produces a deprecation warning.
impl<C> CallbackRef<ThreadSafe, C> where
C: CallbackSignature,
[src]
C: CallbackSignature,
#[must_use]pub fn prefer_thread_safe(self) -> Self
[src]
Gently nudges the compiler to choose the ThreadSafe
version of a value if both are possible.
This method is by value, so it will resolve with higher priority than the by-reference method on the ThreadBound
type.
Note that not all tooling will show the correct overload here, but the compiler knows which to pick.
#[must_use]pub fn prefer_thread_safe_ref(&self) -> &Self
[src]
Gently nudges the compiler to choose the ThreadSafe
version of a reference if both are possible.
This method is once by single reference, so it will resolve with higher priority than the twice-by-reference method on the ThreadBound
type.
Note that not all tooling will show the correct overload here, but the compiler knows which to pick.
impl<C> CallbackRef<ThreadBound, C> where
C: CallbackSignature,
[src]
C: CallbackSignature,
#[must_use]pub fn prefer_thread_safe(&self) -> Self
[src]
Gently nudges the compiler to choose the ThreadSafe
version of a value if both are is possible.
This method is by reference, so it will resolve with lower priority than the by-value method on the ThreadSafe
type.
Note that not all tooling will show the correct overload here, but the compiler knows which to pick.
#[must_use]pub fn prefer_thread_safe_ref<'b>(self: &&'b Self) -> &'b Self
[src]
Gently nudges the compiler to choose the ThreadSafe
version of a reference if both are is possible.
This method is twice by reference, so it will resolve with lower priority than the once-by-reference method on the ThreadSafe
type.
Note that not all tooling will show the correct overload here, but the compiler knows which to pick.
impl<S> CallbackRef<S, fn(event: Event)> where
S: ThreadSafety,
[src]
S: ThreadSafety,
Separate impl
s due to Rust language limitation. See CallbackSignature
and expect future broadening.
pub fn call(self, parameter: Event)
[src]
Invokes the stored handler with the stored receiver and parameter
,
provided that the original CallbackRegistration
hasn’t been dropped yet.
impl<S, T> CallbackRef<S, fn(dom_ref: DomRef<&T>)> where
S: ThreadSafety,
[src]
S: ThreadSafety,
Separate impl
s due to Rust language limitation. See CallbackSignature
and expect future broadening.
pub fn call(self, parameter: DomRef<&T>)
[src]
Invokes the stored handler with the stored receiver and parameter
,
provided that the original CallbackRegistration
hasn’t been dropped yet.
impl<S, C: ?Sized> CallbackRef<S, C> where
S: ThreadSafety,
C: CallbackSignature,
[src]
S: ThreadSafety,
C: CallbackSignature,
These functions are intended as storage optimization for in-browser renderers.
The CallbackRef
’s raw numerical value can be passed through JavaScript directly,
rather than adding another layer of indirection.
Only available with the "callbacks"
feature.
Most DOM renderers will still require an event listener table in order to unsubscribe from events.
Example
use js_sys::Function; use lignin::{CallbackRef, ThreadBound, web}; use wasm_bindgen::{closure::Closure, JsCast, JsValue, UnwrapThrowExt}; let element: web_sys::Element = // … let callback_ref: CallbackRef<ThreadBound, fn(web::Event)> = // … let common_handler = Closure::<dyn Fn(JsValue, web_sys::Event)>::wrap( Box::new(|callback_ref: JsValue, event: web_sys::Event| { unsafe { CallbackRef::<ThreadBound, fn(web::Event)>::from_js(&callback_ref) } .expect_throw("Invalid `CallbackRef`.") .call(event.into()); }) ); let listener = common_handler.as_ref().unchecked_ref::<Function>() .bind1(&JsValue::UNDEFINED, &callback_ref.into_js()); // `common_handler` must be either leaked or stored somewhere, // since otherwise it will throw when called from JavaScript. let result = element.add_event_listener_with_callback("click", &listener);
#[must_use]pub fn into_js(self) -> JsValue
[src]
Returns this CallbackRef
’s identity as JsValue
,
which can then for example be bound
to a generic event handler shim.
Implementation Contract
The return value of this function must be treated as opaque handle.
#[must_use]pub unsafe fn from_js(key: &JsValue) -> Option<Self>
[src]
Reconstructs a CallbackRef
that was previously converted into a JsValue
.
Safety
key
must have been retrieved verbatim from [.into_js
],S
must be compatible (i.e. the same orThreadBound
),- if the original
S
wasThreadBound
, theCallbackRef
must be reconstructed on the same thread and C
must be the same except for lifetime changes that would be okay in an assignment.
Trait Implementations
impl<S1, S2, C> Align<CallbackRef<S2, C>> for CallbackRef<S1, C> where
C: CallbackSignature,
S1: ThreadSafety + Into<S2>,
S2: ThreadSafety,
[src]
C: CallbackSignature,
S1: ThreadSafety + Into<S2>,
S2: ThreadSafety,
impl<S, C> Clone for CallbackRef<S, C> where
S: ThreadSafety,
C: CallbackSignature,
[src]
S: ThreadSafety,
C: CallbackSignature,
fn clone(&self) -> Self
[src]
pub fn clone_from(&mut self, source: &Self)
1.0.0[src]
impl<S, C> Copy for CallbackRef<S, C> where
S: ThreadSafety,
C: CallbackSignature,
[src]
S: ThreadSafety,
C: CallbackSignature,
impl<C, O> Deanonymize<CallbackRef<ThreadSafe, C>> for O where
C: CallbackSignature,
O: Send + Sync + AutoSafe<CallbackRef<ThreadBound, C>>,
[src]
C: CallbackSignature,
O: Send + Sync + AutoSafe<CallbackRef<ThreadBound, C>>,
#[must_use]fn deanonymize(self) -> SafeVariant
[src]
impl<S, C> Debug for CallbackRef<S, C> where
S: ThreadSafety,
C: CallbackSignature,
[src]
S: ThreadSafety,
C: CallbackSignature,
impl<S, C> Eq for CallbackRef<S, C> where
S: ThreadSafety,
C: CallbackSignature,
[src]
S: ThreadSafety,
C: CallbackSignature,
impl<R, C> From<&'_ CallbackRegistration<R, C>> for CallbackRef<ThreadSafe, C> where
R: Sync,
C: CallbackSignature,
[src]
R: Sync,
C: CallbackSignature,
fn from(registration: &CallbackRegistration<R, C>) -> Self
[src]
impl<R, C> From<&'_ CallbackRegistration<R, C>> for CallbackRef<ThreadBound, C> where
C: CallbackSignature,
[src]
C: CallbackSignature,
fn from(registration: &CallbackRegistration<R, C>) -> Self
[src]
impl<C> From<CallbackRef<ThreadSafe, C>> for CallbackRef<ThreadBound, C> where
C: CallbackSignature,
[src]
C: CallbackSignature,
fn from(thread_safe: CallbackRef<ThreadSafe, C>) -> Self
[src]
impl<S, C> Hash for CallbackRef<S, C> where
S: ThreadSafety,
C: CallbackSignature,
[src]
S: ThreadSafety,
C: CallbackSignature,
fn hash<H: Hasher>(&self, state: &mut H)
[src]
pub fn hash_slice<H>(data: &[Self], state: &mut H) where
H: Hasher,
1.3.0[src]
H: Hasher,
impl<S, C> Ord for CallbackRef<S, C> where
S: ThreadSafety,
C: CallbackSignature,
[src]
S: ThreadSafety,
C: CallbackSignature,
fn cmp(&self, other: &Self) -> Ordering
[src]
#[must_use]pub fn max(self, other: Self) -> Self
1.21.0[src]
#[must_use]pub fn min(self, other: Self) -> Self
1.21.0[src]
#[must_use]pub fn clamp(self, min: Self, max: Self) -> Self
1.50.0[src]
impl<S1, S2, C> PartialEq<CallbackRef<S2, C>> for CallbackRef<S1, C> where
S1: ThreadSafety,
S2: ThreadSafety,
C: CallbackSignature,
[src]
S1: ThreadSafety,
S2: ThreadSafety,
C: CallbackSignature,
fn eq(&self, other: &CallbackRef<S2, C>) -> bool
[src]
#[must_use]pub fn ne(&self, other: &Rhs) -> bool
1.0.0[src]
impl<S1, S2, C> PartialOrd<CallbackRef<S2, C>> for CallbackRef<S1, C> where
S1: ThreadSafety,
S2: ThreadSafety,
C: CallbackSignature,
[src]
S1: ThreadSafety,
S2: ThreadSafety,
C: CallbackSignature,
fn partial_cmp(&self, other: &CallbackRef<S2, C>) -> Option<Ordering>
[src]
#[must_use]pub fn lt(&self, other: &Rhs) -> bool
1.0.0[src]
#[must_use]pub fn le(&self, other: &Rhs) -> bool
1.0.0[src]
#[must_use]pub fn gt(&self, other: &Rhs) -> bool
1.0.0[src]
#[must_use]pub fn ge(&self, other: &Rhs) -> bool
1.0.0[src]
impl<S, C> Vdom for CallbackRef<S, C> where
S: ThreadSafety,
C: CallbackSignature,
[src]
S: ThreadSafety,
C: CallbackSignature,
type ThreadSafety = S
The ThreadSafety
of the Vdom
type, either ThreadSafe
or ThreadBound
. Read more
Auto Trait Implementations
impl<S, C> RefUnwindSafe for CallbackRef<S, C> where
C: RefUnwindSafe,
S: RefUnwindSafe,
C: RefUnwindSafe,
S: RefUnwindSafe,
impl<S, C> Send for CallbackRef<S, C> where
C: Send,
S: Send,
C: Send,
S: Send,
impl<S, C> Sync for CallbackRef<S, C> where
C: Sync,
S: Sync,
C: Sync,
S: Sync,
impl<S, C> Unpin for CallbackRef<S, C> where
C: Unpin,
S: Unpin,
C: Unpin,
S: Unpin,
impl<S, C> UnwindSafe for CallbackRef<S, C> where
C: UnwindSafe,
S: UnwindSafe,
C: UnwindSafe,
S: UnwindSafe,
Blanket Implementations
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<'a, S, T> AutoSafe<T> for S where
S: Vdom + Align<T>,
T: Vdom<ThreadSafety = ThreadBound>,
[src]
S: Vdom + Align<T>,
T: Vdom<ThreadSafety = ThreadBound>,
#[must_use]fn deanonymize(&self) -> BoundVariant
[src]
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
pub fn borrow_mut(&mut self) -> &mut T
[src]
impl<C, O> Deanonymize<CallbackRef<ThreadSafe, C>> for O where
C: CallbackSignature,
O: Send + Sync + AutoSafe<CallbackRef<ThreadBound, C>>,
[src]
C: CallbackSignature,
O: Send + Sync + AutoSafe<CallbackRef<ThreadBound, C>>,
#[must_use]fn deanonymize(self) -> SafeVariant
[src]
impl<T> From<T> for T
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T> ToOwned for T where
T: Clone,
[src]
T: Clone,
type Owned = T
The resulting type after obtaining ownership.
pub fn to_owned(&self) -> T
[src]
pub fn clone_into(&self, target: &mut T)
[src]
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
pub fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,