Skip to main content

EventDetail

Enum EventDetail 

Source
#[non_exhaustive]
pub enum EventDetail { None, String(String), Transition(Box<TransitionDetail>), Input(Box<InputDetail>), Submit(Box<SubmitDetail>), Toggle(Box<ToggleDetail>), Mouse(MouseDetail), Keyboard(Box<KeyboardDetail>), }
Expand description

Typed payload carried on Event::detail.

Replaces the pre-M4 Option<String> detail with a closed enum of typed variants. The EventDetail::String variant preserves the one-shot escape hatch authors used to lean on via Event::new("custom").with_detail("payload").

§Variant boxing

Variants whose largest field is a String are boxed; inline for fixed-size variants. This keeps the enum under 32 bytes on 64-bit (a const-assert below enforces that).

§Accessor pattern

Listeners read typed detail through the as_* accessors:

let mut e = Event::new("custom");
e.detail = EventDetail::String("payload".into());
assert_eq!(e.detail.as_string(), Some("payload"));

Variants (Non-exhaustive)§

This enum is marked as non-exhaustive
Non-exhaustive enums could have additional variants added in future. Therefore, when matching against variants of non-exhaustive enums, an extra wildcard arm must be added to account for any future variants.
§

None

No detail attached. Default for plain events (click, focus, blur, …) and the initial state on Event::new.

§

String(String)

Free-form string payload. Used for CustomEvent-style author-fired events; also the migration target for any pre-M4 reader that stored a string in Option<String>.

§

Transition(Box<TransitionDetail>)

transitionstart / transitionend / transitioncancel payload — emitted by runtime::animation.

§

Input(Box<InputDetail>)

beforeinput / input event payload — emitted by <input> / <textarea> and contenteditable elements.

§

Submit(Box<SubmitDetail>)

submit event payload — emitted by <form>.

§

Toggle(Box<ToggleDetail>)

toggle event payload — emitted by <details> and <dialog>.

§

Mouse(MouseDetail)

Pointer event payload — click / mousedown / mouseup / mousemove / wheel / contextmenu. Inline; the struct is fixed-size.

§

Keyboard(Box<KeyboardDetail>)

keydown / keypress / keyup payload. Boxed because the inner key: String would otherwise push the enum past its 32-byte budget.

Implementations§

Source§

impl EventDetail

Source

pub fn as_string(&self) -> Option<&str>

Borrow the payload as a &str iff this is EventDetail::String. Returns None for every other variant — typed-detail readers should use the matching as_* accessor instead.

Source

pub fn as_transition(&self) -> Option<&TransitionDetail>

Borrow the transition payload iff this is EventDetail::Transition.

Source

pub fn as_input(&self) -> Option<&InputDetail>

Borrow the input payload iff this is EventDetail::Input.

Source

pub fn as_submit(&self) -> Option<&SubmitDetail>

Borrow the submit payload iff this is EventDetail::Submit.

Source

pub fn as_toggle(&self) -> Option<&ToggleDetail>

Borrow the toggle payload iff this is EventDetail::Toggle.

Source

pub fn as_mouse(&self) -> Option<&MouseDetail>

Borrow the mouse payload iff this is EventDetail::Mouse.

Source

pub fn as_keyboard(&self) -> Option<&KeyboardDetail>

Borrow the keyboard payload iff this is EventDetail::Keyboard.

Trait Implementations§

Source§

impl Clone for EventDetail

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

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

Performs copy-assignment from source. Read more
Source§

impl Debug for EventDetail

Source§

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

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

impl Default for EventDetail

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl PartialEq for EventDetail

Source§

fn eq(&self, other: &Self) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

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

Inequality operator !=. Read more
Source§

impl StructuralPartialEq for EventDetail

Auto Trait Implementations§

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> 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<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 = !

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

fn try_from(value: U) -> Result<T, !>

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.