#[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
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
impl EventDetail
Sourcepub fn as_string(&self) -> Option<&str>
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.
Sourcepub fn as_transition(&self) -> Option<&TransitionDetail>
pub fn as_transition(&self) -> Option<&TransitionDetail>
Borrow the transition payload iff this is
EventDetail::Transition.
Sourcepub fn as_input(&self) -> Option<&InputDetail>
pub fn as_input(&self) -> Option<&InputDetail>
Borrow the input payload iff this is
EventDetail::Input.
Sourcepub fn as_submit(&self) -> Option<&SubmitDetail>
pub fn as_submit(&self) -> Option<&SubmitDetail>
Borrow the submit payload iff this is
EventDetail::Submit.
Sourcepub fn as_toggle(&self) -> Option<&ToggleDetail>
pub fn as_toggle(&self) -> Option<&ToggleDetail>
Borrow the toggle payload iff this is
EventDetail::Toggle.
Sourcepub fn as_mouse(&self) -> Option<&MouseDetail>
pub fn as_mouse(&self) -> Option<&MouseDetail>
Borrow the mouse payload iff this is
EventDetail::Mouse.
Sourcepub fn as_keyboard(&self) -> Option<&KeyboardDetail>
pub fn as_keyboard(&self) -> Option<&KeyboardDetail>
Borrow the keyboard payload iff this is
EventDetail::Keyboard.