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 create_reactive_style<F>(compute: F) -> Self
where F: Fn() -> String + 'static,

Creates a reactive style Self that updates when signals change.

This function replaces the inline Signal::create(...) + subscribe_attr_signal(...) boilerplate that was previously generated by the html! macro for every style: attribute containing reactive if conditions.

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

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

Creates a reactive attribute Self for conditional attribute values.

This function replaces the inline Signal::create(...) + subscribe_attr_signal(...) 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: &[Self]) -> Self

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: &[Self]) -> Self

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

Formats the value using the given formatter. Read more
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: &Self) -> 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: 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