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, the handler is
re-wrapped with the given event_name to ensure the DOM event listener
is bound to the correct event type (e.g., “click” rather than “onclick”).
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
Converts the wrapped handler into an event AttributeValue.
Re-wraps the handler with the provided event_name so that the
DOM event listener uses the correct event type string.
§Arguments
NativeEventName- The event name to bind the handler to.
§Returns
AttributeValue- AnAttributeValue::Eventcontaining the re-wrapped handler.
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) re-wrapped with the
given event name, and None becomes AttributeValue::Text(String::new()).
This replaces the impl __EventWrapper<Option<NativeEventHandler>> 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
Converts the wrapped optional handler into an attribute value.
Re-wraps a Some handler with the provided event_name so that the
DOM event listener uses the correct event type string.
§Arguments
NativeEventName- The event name to bind the handler to.
§Returns
AttributeValue- An event attribute ifSome, otherwise an empty text attribute.