Listener

Struct Listener 

Source
pub struct Listener<Element: Deref<Target = EventTarget>, Arg: FromWasmAbi + 'static = JsValue> { /* private fields */ }
Expand description

Safe wrapper around eventListener callbacks that cleans them up once the Listener struct is dropped For more information, see https://github.com/rustwasm/wasm-bindgen/issues/993.

This utility can be used with any type that dereferences to EventTarget, so it is not limited to just pure HtmlElements.

Implementations§

Source§

impl<Element: Deref<Target = EventTarget>, Arg: FromWasmAbi + 'static> Listener<Element, Arg>

Source

pub fn new<F>(element: Element, name: &'static str, cb: F) -> Self
where F: Fn(Arg) + 'static,

Attaches a listener callback to an element

Source

pub fn element(&self) -> &Element

Get the element that this listener is attached to

Source

pub fn name(&self) -> &'static str

Get the name of the event that this listener is listening for

Source

pub fn callback(&self) -> &Closure<dyn Fn(Arg)>

Get the callback that is called when the listener’s event is emitted

Trait Implementations§

Source§

impl<Element: Debug + Deref<Target = EventTarget>, Arg: Debug + FromWasmAbi + 'static> Debug for Listener<Element, Arg>

Source§

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

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

impl<Element: Deref<Target = EventTarget>, Arg: FromWasmAbi + 'static> Drop for Listener<Element, Arg>

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more

Auto Trait Implementations§

§

impl<Element, Arg> Freeze for Listener<Element, Arg>
where Element: Freeze,

§

impl<Element, Arg = JsValue> !RefUnwindSafe for Listener<Element, Arg>

§

impl<Element, Arg = JsValue> !Send for Listener<Element, Arg>

§

impl<Element, Arg = JsValue> !Sync for Listener<Element, Arg>

§

impl<Element, Arg> Unpin for Listener<Element, Arg>
where Element: Unpin,

§

impl<Element, Arg = JsValue> !UnwindSafe for Listener<Element, Arg>

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<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> 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, 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.