Skip to main content

AttrValueAdapter

Struct AttrValueAdapter 

Source
pub struct AttrValueAdapter<T> { /* private fields */ }
Expand description

Adapts an arbitrary attribute value expression into an AttributeValue.

Handles the dispatch between event closures and reactive values without requiring the macro to generate inline trait hierarchies. The macro emits AttrValueAdapter::new(expr).into_attribute_value() instead of the __IsClosure / __ClosurePicker / __ValuePicker / __FallbackHelper / __dispatch boilerplate.

For event attributes (key starts with “on”), event closures are wrapped into AttributeValue::Event. For non-event attributes, values are converted via IntoReactiveValue.

Implementations§

Source§

impl<T> AttrValueAdapter<T>

Constructs an AttrValueAdapter that wraps any attribute-compatible value.

Source

pub fn new(inner: T) -> Self

Creates a new AttrValueAdapter wrapping the given value.

§Arguments
  • T - The value to wrap for attribute adaptation.
§Returns
  • AttrValueAdapter<T> - A new adapter wrapping the value.
Source§

impl<F> AttrValueAdapter<F>
where F: FnMut(NativeEvent) + 'static,

Adapts a FnMut(NativeEvent) closure into a callback AttributeValue.

This handles the case where a closure is used as a component callback prop. The closure is converted via IntoCallbackAttribute::into_callback_attribute(). This replaces the __IsClosure for F impl that was previously generated inline.

Source

pub fn into_callback_attribute_value(self) -> AttributeValue

Converts the wrapped closure into a callback AttributeValue.

§Returns
  • AttributeValue - An event attribute value wrapping the adapted closure.
Source

pub fn into_callback_attribute_value_with_name( self, name: String, ) -> AttributeValue

Converts the wrapped closure into a callback AttributeValue with a custom event name for component props.

§Arguments
  • String - The custom attribute name (e.g., “on-increment”, “on-change”).
§Returns
  • AttributeValue - An event attribute value with the custom name.
Source§

impl AttrValueAdapter<NativeEventHandler>

Adapts an owned NativeEventHandler into an AttributeValue::Event directly.

When the user already provides a NativeEventHandler, the handler is re-wrapped with a generic “callback” event name so that subsequent EventAdapter::into_attribute calls can override it with the correct DOM event type. This replaces the __IsClosure for NativeEventHandler impl that was previously generated inline by the html! macro.

Source

pub fn into_callback_attribute_value(self) -> AttributeValue

Converts the wrapped handler into an event AttributeValue.

Re-wraps the handler with a generic callback event name so that the DOM event type can be correctly resolved when the handler is later bound to a real element via EventAdapter::into_attribute.

§Returns
  • AttributeValue - An AttributeValue::Event containing the re-wrapped handler.
Source

pub fn into_callback_attribute_value_with_name( self, name: String, ) -> AttributeValue

Converts the wrapped handler into a callback AttributeValue with a custom event name for component props.

§Arguments
  • String - The custom attribute name.
§Returns
  • AttributeValue - An event attribute value with the custom name.
Source§

impl AttrValueAdapter<Option<NativeEventHandler>>

Adapts an Option<NativeEventHandler> into an AttributeValue.

Some(handler) becomes AttributeValue::Event(handler) re-wrapped with a generic callback event name, and None becomes AttributeValue::Text(String::new()). This replaces the __IsClosure for Option<NativeEventHandler> impl that was previously generated inline by the html! macro.

Source

pub fn into_callback_attribute_value(self) -> AttributeValue

Converts the wrapped optional handler into an attribute value.

Re-wraps a Some handler with a generic callback event name so that the DOM event type can be correctly resolved when the handler is later bound to a real element via EventAdapter::into_attribute.

§Returns
  • AttributeValue - An event attribute if Some, otherwise an empty text attribute.
Source

pub fn into_callback_attribute_value_with_name( self, name: String, ) -> AttributeValue

Converts this optional handler into a callback AttributeValue with a custom event name for component props.

§Arguments
  • String - The custom attribute name.
§Returns
  • AttributeValue - An event attribute with the custom name if Some, otherwise an empty text attribute.
Source§

impl<T> AttrValueAdapter<T>

Adapts any IntoReactiveValue type into an AttributeValue.

This is the fallback path for non-closure attribute values (strings, signals, CSS classes, etc.). The value is converted via IntoReactiveValue::into_reactive_value(). This replaces the __ValuePicker / __FallbackHelper hierarchy that was previously generated inline by the html! macro.

Source

pub fn into_reactive_attribute_value(self) -> AttributeValue

Converts the wrapped value into an AttributeValue via reactive value adaptation.

§Returns
  • AttributeValue - The reactive attribute value.

Auto Trait Implementations§

§

impl<T> Freeze for AttrValueAdapter<T>
where T: Freeze,

§

impl<T> RefUnwindSafe for AttrValueAdapter<T>
where T: RefUnwindSafe,

§

impl<T> Send for AttrValueAdapter<T>
where T: Send,

§

impl<T> Sync for AttrValueAdapter<T>
where T: Sync,

§

impl<T> Unpin for AttrValueAdapter<T>
where T: Unpin,

§

impl<T> UnsafeUnpin for AttrValueAdapter<T>
where T: UnsafeUnpin,

§

impl<T> UnwindSafe for AttrValueAdapter<T>
where T: UnwindSafe,

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.
Source§

impl<S, T> Upcast<T> for S
where T: UpcastFrom<S> + ?Sized, S: ?Sized,

Source§

fn upcast(&self) -> &T
where Self: ErasableGeneric, T: ErasableGeneric<Repr = Self::Repr>,

Perform a zero-cost type-safe upcast to a wider ref type within the Wasm bindgen generics type system. Read more
Source§

fn upcast_into(self) -> T
where Self: Sized + ErasableGeneric, T: ErasableGeneric<Repr = Self::Repr>,

Perform a zero-cost type-safe upcast to a wider type within the Wasm bindgen generics type system. Read more