Struct CallbackRef

Source
pub struct CallbackRef<S, C>{ /* private fields */ }
Expand description

Vdom A callback reference linked to a CallbackRegistration.

Implementations§

Source§

impl<S: ThreadSafety, C> CallbackRef<S, C>

Source

pub fn deanonymize(self) -> Self

👎Deprecated: 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.

Source§

impl<C> CallbackRef<ThreadSafe, C>

Source

pub fn prefer_thread_safe(self) -> Self

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.

Source

pub fn prefer_thread_safe_ref(&self) -> &Self

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.

Source§

impl<C> CallbackRef<ThreadBound, C>

Source

pub fn prefer_thread_safe(&self) -> Self

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.

Source

pub fn prefer_thread_safe_ref<'b>(self: &&'b Self) -> &'b Self

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.

Source§

impl<S> CallbackRef<S, fn(event: Event)>
where S: ThreadSafety,

Separate impls due to Rust language limitation. See CallbackSignature and expect future broadening.

Source

pub fn call(self, parameter: Event)

Invokes the stored handler with the stored receiver and parameter, provided that the original CallbackRegistration hasn’t been dropped yet.

Source§

impl<S, T> CallbackRef<S, fn(dom_ref: DomRef<&T>)>
where S: ThreadSafety,

Separate impls due to Rust language limitation. See CallbackSignature and expect future broadening.

Source

pub fn call(self, parameter: DomRef<&T>)

Invokes the stored handler with the stored receiver and parameter, provided that the original CallbackRegistration hasn’t been dropped yet.

Source§

impl<S, C> CallbackRef<S, C>

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);
Source

pub fn into_js(self) -> JsValue

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.

Source

pub unsafe fn from_js(key: &JsValue) -> Option<Self>

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 or ThreadBound),
  • if the original S was ThreadBound, the CallbackRef 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§

Source§

impl<S1, S2, C> Align<CallbackRef<S2, C>> for CallbackRef<S1, C>

Source§

fn align(self) -> T

Contextually thread-binds an instance, or not. Use only without qualification.
Source§

fn align_ref(&self) -> &T

Contextually thread-binds a reference, or not. Use only without qualification.
Source§

impl<S, C> Clone for CallbackRef<S, C>

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<S, C> Debug for CallbackRef<S, C>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<R, C> From<&CallbackRegistration<R, C>> for CallbackRef<ThreadBound, C>

Source§

fn from(registration: &CallbackRegistration<R, C>) -> Self

Converts to this type from the input type.
Source§

impl<R, C> From<&CallbackRegistration<R, C>> for CallbackRef<ThreadSafe, C>
where R: Sync, C: CallbackSignature,

Source§

fn from(registration: &CallbackRegistration<R, C>) -> Self

Converts to this type from the input type.
Source§

impl<C> From<CallbackRef<ThreadSafe, C>> for CallbackRef<ThreadBound, C>

Source§

fn from(thread_safe: CallbackRef<ThreadSafe, C>) -> Self

Converts to this type from the input type.
Source§

impl<S, C> Hash for CallbackRef<S, C>

Source§

fn hash<H: Hasher>(&self, state: &mut H)

Feeds this value into the given Hasher. Read more
1.3.0 · Source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
Source§

impl<S, C> Ord for CallbackRef<S, C>

Source§

fn cmp(&self, other: &Self) -> Ordering

This method returns an Ordering between self and other. Read more
1.21.0 · Source§

fn max(self, other: Self) -> Self
where Self: Sized,

Compares and returns the maximum of two values. Read more
1.21.0 · Source§

fn min(self, other: Self) -> Self
where Self: Sized,

Compares and returns the minimum of two values. Read more
1.50.0 · Source§

fn clamp(self, min: Self, max: Self) -> Self
where Self: Sized,

Restrict a value to a certain interval. Read more
Source§

impl<S1, S2, C> PartialEq<CallbackRef<S2, C>> for CallbackRef<S1, C>

Source§

fn eq(&self, other: &CallbackRef<S2, C>) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl<S1, S2, C> PartialOrd<CallbackRef<S2, C>> for CallbackRef<S1, C>

Source§

fn partial_cmp(&self, other: &CallbackRef<S2, C>) -> Option<Ordering>

This method returns an ordering between self and other values if one exists. Read more
1.0.0 · Source§

fn lt(&self, other: &Rhs) -> bool

Tests less than (for self and other) and is used by the < operator. Read more
1.0.0 · Source§

fn le(&self, other: &Rhs) -> bool

Tests less than or equal to (for self and other) and is used by the <= operator. Read more
1.0.0 · Source§

fn gt(&self, other: &Rhs) -> bool

Tests greater than (for self and other) and is used by the > operator. Read more
1.0.0 · Source§

fn ge(&self, other: &Rhs) -> bool

Tests greater than or equal to (for self and other) and is used by the >= operator. Read more
Source§

impl<S, C> Vdom for CallbackRef<S, C>

Source§

impl<S, C> Copy for CallbackRef<S, C>

Source§

impl<S, C> Eq for CallbackRef<S, C>

Auto Trait Implementations§

§

impl<S, C> Freeze for CallbackRef<S, C>

§

impl<S, C> RefUnwindSafe for CallbackRef<S, C>

§

impl<S, C> Send for CallbackRef<S, C>
where S: Send, C: Send,

§

impl<S, C> Sync for CallbackRef<S, C>
where S: Sync, C: Sync,

§

impl<S, C> Unpin for CallbackRef<S, C>
where S: Unpin, C: Unpin,

§

impl<S, C> UnwindSafe for CallbackRef<S, C>
where S: UnwindSafe, C: UnwindSafe,

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<'a, S, T> AutoSafe<T> for S
where S: Vdom + Align<T>, T: Vdom<ThreadSafety = ThreadBound>,

Source§

fn deanonymize(&self) -> BoundVariant

Deanonymize towards a compatible concrete type. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<C, O> Deanonymize<CallbackRef<ThreadSafe, C>> for O

Source§

fn deanonymize(self) -> SafeVariant

Deanonymize towards a compatible concrete type. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.