Skip to main content

AttributeValue

Enum AttributeValue 

Source
pub enum AttributeValue {
    Text(String),
    Signal(Signal<String>),
    Event(NativeEventHandler),
    Dynamic(String),
    Css(Css),
}
Expand description

Represents the value of an HTML attribute.

Attributes can be static text, reactive signals, event handlers, dynamic expressions, or CSS class references.

Variants§

§

Text(String)

A static string value.

§

Signal(Signal<String>)

A dynamic signal-backed value.

§

Event(NativeEventHandler)

An event handler callback.

§

Dynamic(String)

A dynamic expression value of any type (for component props).

§

Css(Css)

A CSS class reference created by the class! macro.

Implementations§

Source§

impl AttributeValue

Implementation of attribute value factory methods for reactive and merged values.

Source

pub fn reactive<F>(compute: F) -> AttributeValue
where F: Fn() -> String + 'static,

Creates a reactive attribute Self for conditional attribute values.

This function replaces the inline Signal::create(...) + subscribe_attr(...) boilerplate that was previously generated by the html! macro for every attribute value containing an if condition.

§Arguments
  • Fn() -> String + 'static - A closure that computes the current attribute value. Called on initial render and whenever any signal changes.
§Returns
  • Self - A Self::Signal backed by a Signal<String> that reactively re-evaluates the attribute value on signal updates.
Source

pub fn merge_class(values: &[AttributeValue]) -> AttributeValue

Merges multiple class attribute values into a single Self.

Each input value is adapted into a Self via IntoReactiveValue. Css values are injected into the DOM and their names are collected. All non-empty class names are joined with spaces into a final Text attribute. If any value is signal-backed, the result becomes a reactive Signal attribute that re-evaluates when any constituent signal changes.

§Arguments
  • &[Self] - The class attribute values to merge.
§Returns
  • Self - A merged attribute value containing space-separated class names.
Source

pub fn merge_style(values: &[AttributeValue]) -> AttributeValue

Merges multiple style attribute values into a single Self.

Each input value is expected to be a style string (Text) or a reactive Signal<String> producing a style string. All non-empty style strings are joined with spaces into a final combined style attribute. If any value is signal-backed, the result becomes a reactive Signal attribute.

§Arguments
  • &[Self] - The style attribute values to merge.
§Returns
  • Self - A merged attribute value containing the combined CSS style string.

Trait Implementations§

Source§

impl Clone for AttributeValue

Source§

fn clone(&self) -> AttributeValue

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 AttributeValue

Source§

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

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

impl From<&'static Css> for AttributeValue

Converts a reference to a CSS class into an attribute value by cloning.

Source§

fn from(css: &'static Css) -> AttributeValue

Converts this CSS class reference into an AttributeValue::Css by cloning.

§Returns
  • AttributeValue - A CSS class attribute value.
Source§

impl From<&str> for AttributeValue

Converts a string slice into a text attribute value.

Source§

fn from(value: &str) -> AttributeValue

Converts this string slice into an AttributeValue::Text.

§Returns
  • AttributeValue - A text attribute value containing the owned string.
Source§

impl<T> From<AttrValueAdapter<T>> for AttributeValue
where T: Into<AttributeValue>,

Adapts any type that implements Into<AttributeValue> into an AttributeValue.

This is the fallback path for non-closure attribute values (strings, signals, CSS classes, etc.).

Source§

fn from(adapter: AttrValueAdapter<T>) -> AttributeValue

Converts the wrapped value into an AttributeValue.

§Returns
  • AttributeValue - The reactive attribute value.
Source§

impl<F> From<CallbackNamedAdapter<F>> for AttributeValue
where F: FnMut(Event) + 'static,

Converts a named callback adapter into an AttributeValue.

Source§

fn from(adapter: CallbackNamedAdapter<F>) -> AttributeValue

Converts the wrapped closure with custom name into a callback AttributeValue.

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

impl From<Css> for AttributeValue

Converts a CSS class reference into an attribute value.

Source§

fn from(css: Css) -> AttributeValue

Converts this CSS class into an AttributeValue::Css.

§Returns
  • AttributeValue - A CSS class attribute value.
Source§

impl<F> From<EventNamedAdapter<F>> for AttributeValue
where F: FnMut(Event) + 'static,

Converts an event with a specific event name into an AttributeValue.

Source§

fn from(adapter: EventNamedAdapter<F>) -> AttributeValue

Converts the wrapped closure with event name into an event AttributeValue.

§Returns
  • AttributeValue - An AttributeValue::Event wrapping the handler.
Source§

impl From<EventNamedAdapter<NativeEventHandler>> for AttributeValue

Converts an event named adapter with NativeEventHandler into an AttributeValue.

Source§

fn from(adapter: EventNamedAdapter<NativeEventHandler>) -> AttributeValue

Converts the wrapped handler with event name into an event AttributeValue.

§Returns
  • AttributeValue - An AttributeValue::Event wrapping the handler.
Source§

impl From<EventNamedAdapter<Option<Rc<dyn Fn(Event)>>>> for AttributeValue

Converts an event named adapter with optional shared closure into an AttributeValue.

Some(callback) becomes AttributeValue::Event by wrapping the shared closure into a NativeEventHandler with the adapter’s event name, and None becomes AttributeValue::Text(String::new()).

Source§

fn from(adapter: EventNamedAdapter<Option<Rc<dyn Fn(Event)>>>) -> AttributeValue

Converts the wrapped optional shared closure with event name into an event AttributeValue.

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

impl<F> From<F> for AttributeValue
where F: FnMut(Event) + 'static,

Converts a closure into a callback attribute value.

Source§

fn from(closure: F) -> AttributeValue

Wraps this closure into an AttributeValue::Event with a generic “callback” event name.

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

impl From<NativeEventHandler> for AttributeValue

Converts an owned event handler into a callback attribute value.

Re-wraps the handler with a generic “callback” event name so that subsequent EventAdapter::into_attribute calls can override it with the correct DOM event type.

Source§

fn from(handler: NativeEventHandler) -> AttributeValue

Converts this event handler into an AttributeValue::Event.

§Returns
  • AttributeValue - An event attribute value with a generic callback event name.
Source§

impl From<Option<NativeEventHandler>> for AttributeValue

Converts an optional event handler into a callback attribute value.

Re-wraps a Some handler with a generic “callback” event name so that subsequent EventAdapter::into_attribute calls can override it with the correct DOM event type.

Source§

fn from(handler: Option<NativeEventHandler>) -> AttributeValue

Converts this optional handler into an AttributeValue::Event or AttributeValue::Text if None.

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

impl From<Option<Signal<String>>> for AttributeValue

Converts an optional string signal into a reactive or empty attribute value.

Some(signal) becomes AttributeValue::Signal, None becomes AttributeValue::Text(String::new()). This supports component props that use Option<Signal<String>> for optional reactive attributes.

Source§

fn from(signal: Option<Signal<String>>) -> AttributeValue

Converts to this type from the input type.
Source§

impl From<Signal<String>> for AttributeValue

Converts a string signal into a reactive attribute value.

Source§

fn from(signal: Signal<String>) -> AttributeValue

Converts this string signal into an AttributeValue::Signal.

§Returns
  • AttributeValue - A signal-backed attribute value.
Source§

impl From<Signal<bool>> for AttributeValue

Converts a mutable bool signal into a reactive attribute value.

The signal is mapped to a Signal<String> that yields "true" or "false", enabling boolean attributes like checked to reactively update the DOM.

Source§

fn from(signal: Signal<bool>) -> AttributeValue

Converts this bool signal into an AttributeValue via string mapping.

§Returns
  • AttributeValue - A signal-backed attribute value yielding "true" or "false".
Source§

impl From<String> for AttributeValue

Converts a static String into a text attribute value.

Source§

fn from(value: String) -> AttributeValue

Converts this string into an AttributeValue::Text.

§Returns
  • AttributeValue - A text attribute value containing this string.
Source§

impl From<bool> for AttributeValue

Converts a bool into a dynamic attribute value.

Stored as AttributeValue::Dynamic("true"/"false") so components can extract the original boolean via try_get_typed_prop.

Source§

fn from(value: bool) -> AttributeValue

Converts this boolean into an AttributeValue::Dynamic.

§Returns
  • AttributeValue - A dynamic attribute value containing the boolean string.
Source§

impl From<f64> for AttributeValue

Converts an f64 into a dynamic attribute value.

Stored as AttributeValue::Dynamic so components can extract the original float via try_get_typed_prop.

Source§

fn from(value: f64) -> AttributeValue

Converts this float into an AttributeValue::Dynamic.

§Returns
  • AttributeValue - A dynamic attribute value containing the float string.
Source§

impl From<i32> for AttributeValue

Converts an i32 into a dynamic attribute value.

Stored as AttributeValue::Dynamic so components can extract the original integer via try_get_typed_prop.

Source§

fn from(value: i32) -> AttributeValue

Converts this integer into an AttributeValue::Dynamic.

§Returns
  • AttributeValue - A dynamic attribute value containing the integer string.
Source§

impl PartialEq for AttributeValue

Visual equality comparison for attribute values.

Compares values by their visual output rather than identity. Signal values are compared by their current resolved string; when both signals share the same inner pointer, they are always considered unequal because the signal may have mutated between VDOM snapshots and .get() would return the same current value for both, masking the change. Event values are always considered equal (re-binding is handled by the handler registry), and Css values are compared by class name.

Source§

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

Compares two attribute values for visual equality.

§Arguments
  • &Self - The first attribute value.
  • &Self - The second attribute value.
§Returns
  • bool - true if the values are visually equal.
1.0.0 (const: unstable) · Source§

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

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.

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 = 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: Sized + 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: Sized + ErasableGeneric<Repr = Self::Repr>,

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