pub struct EventAdapter<T> { /* private fields */ }Expand description
Adapts various event value types into an AttributeValue for event attributes.
The html! macro generates EventAdapter::new(expr).into_attribute(event_name)
instead of inline trait dispatch boilerplate. This eliminates the per-attribute-site
generation of __EventWrapper, __IsClosure, __ClosurePicker, __ValuePicker,
__FallbackHelper, and __dispatch types, significantly reducing macro output size.
The adapter pattern handles three cases:
FnMut(NativeEvent)closure →AttributeValue::EventviaNativeEventHandlerNativeEventHandlerdirectly →AttributeValue::Eventas-isOption<NativeEventHandler>→AttributeValue::EventorAttributeValue::Text
Implementations§
Source§impl<T> EventAdapter<T>
Constructs an EventAdapter that wraps any event-compatible value.
impl<T> EventAdapter<T>
Constructs an EventAdapter that wraps any event-compatible value.
Source§impl<F> EventAdapter<F>where
F: FnMut(NativeEvent) + 'static,
Adapts a FnMut(NativeEvent) closure into an AttributeValue::Event.
impl<F> EventAdapter<F>where
F: FnMut(NativeEvent) + 'static,
Adapts a FnMut(NativeEvent) closure into an AttributeValue::Event.
Wraps the closure into a NativeEventHandler and returns it as an
event attribute value. This replaces the __EventWrapper<F> type
that was previously generated inline by the html! macro.
Sourcepub fn into_attribute(self, event_name: NativeEventName) -> AttributeValue
pub fn into_attribute(self, event_name: NativeEventName) -> AttributeValue
Source§impl EventAdapter<NativeEventHandler>
Adapts an owned NativeEventHandler into an AttributeValue::Event directly.
impl EventAdapter<NativeEventHandler>
Adapts an owned NativeEventHandler into an AttributeValue::Event directly.
When the user already provides a NativeEventHandler, no wrapping is needed;
the handler is returned as-is. This replaces the impl __EventWrapper<NativeEventHandler>
that was previously generated inline.
Sourcepub fn into_attribute(self, _event_name: NativeEventName) -> AttributeValue
pub fn into_attribute(self, _event_name: NativeEventName) -> AttributeValue
Source§impl EventAdapter<Option<NativeEventHandler>>
Adapts an Option<NativeEventHandler> into an AttributeValue.
impl EventAdapter<Option<NativeEventHandler>>
Adapts an Option<NativeEventHandler> into an AttributeValue.
Some(handler) becomes AttributeValue::Event(handler), and None becomes
AttributeValue::Text(String::new()). This replaces the
impl __EventWrapper<Option<NativeEventHandler>> that was previously
generated inline by the html! macro.