Skip to main content

Style

Struct Style 

Source
pub struct Style { /* private fields */ }
Expand description

A collection of CSS style properties that can be converted to a style string.

Implementations§

Source§

impl Style

Implementation of style CSS serialization.

Source

pub fn property<N, V>(self, name: N, value: V) -> Self
where N: AsRef<str>, V: AsRef<str>,

Adds a style property.

Property names are automatically converted from snake_case to kebab-case (e.g., flex_direction becomes flex-direction).

§Arguments
  • N - The property name (snake_case will be converted to kebab-case).
  • V - The property value.
§Returns
  • Self - This style with the property added.
Source

pub fn to_css_string(&self) -> String

Converts the style to a CSS string.

§Returns
  • String - The CSS string representation.
Source

pub fn create_style_string(props: &[(&str, &str)]) -> String

Builds a CSS style string from an array of key-value pairs.

This function is used by the html! macro to convert static style: attributes into a CSS string without allocating intermediate Style and Vec<StyleProperty> objects. Keys are converted from snake_case to kebab-case automatically.

§Arguments
  • &[(&str, &str)] - An array of CSS property name-value pairs.
§Returns
  • String - The CSS string (e.g., "margin: 0 auto; max-width: 800px;").
Source§

impl Style

Source

pub fn get_properties(&self) -> &Vec<StyleProperty>

Source

pub fn set_properties(&mut self, val: Vec<StyleProperty>) -> &mut Self

Source

pub fn get_mut_properties(&mut self) -> &mut Vec<StyleProperty>

Source§

impl Style

Source

pub fn new(properties: Vec<StyleProperty>) -> Self

Trait Implementations§

Source§

impl Default for Style

Provides a default empty style.

Source§

fn default() -> Self

Returns a default Style with no properties.

§Returns
  • Self - An empty style.

Auto Trait Implementations§

§

impl Freeze for Style

§

impl RefUnwindSafe for Style

§

impl Send for Style

§

impl Sync for Style

§

impl Unpin for Style

§

impl UnsafeUnpin for Style

§

impl UnwindSafe for Style

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