Struct wasm_css::Style

source ·
pub struct Style { /* private fields */ }
Expand description

Represents a CSS Style

Implementations§

source§

impl Style

source

pub fn new(css: String, class: Option<String>) -> Result<Self, WasmCssError>

Construct a Style from a CSS string

  • See style! for built-in formatting

  • Generates random class name if one is not provided, returns WasmCssError if unable to locate Crypto when generating uuid for class name

  • Filters out invalid CSS keys, use Style::new_checked if you would like to handle invalid CSS


Example Usage:


let style: Style = Style::new(
    "
        gap: 10rem;
        display: flex;
        flex-direction: column;
    ",
    None,
)?;
source

pub fn new_checked( css: String, class: Option<String>, ) -> Result<Self, WasmCssError>

Construct a Style from a CSS string with formatting, returning a WasmCssError of the invalid line if encountered during parsing

  • See style_checked! for built-in formatting

  • Generates random class name if one is not provided, returns WasmCssError if unable to locate Crypto when generating uuid for class name


Example Usage:


let style_result: Result<Style, WasmCssError> = Style::new_checked(
    "
        gap: 10rem;
        display: flex;
        flex-direction: column;
    ",
    None,
);
source

pub fn class(&self) -> &String

Returns this Styles class name

source

pub fn append(&mut self, source: &Style) -> Result<(), WasmCssError>

Append another Style to this one, overwriting any fields on self matching with source, or adding them if they did not previously exist, updating the Style


Example Usage:


let mut style_one = style!("color: red; font-size: 10rem;")?;

let style_two = style!("font-size: 30rem; background-color: red;")?;

style_one.append(&style_two)?;

// style_one.css: "color: red; font-size: 30rem; background-color: red;"
source

pub fn insert<V: Into<String>>( &mut self, key: &str, value: V, ) -> Result<(), WasmCssError>

Insert a new CSS line into the Style

  • Skips invalid keys

Example Usage:


let mut style = style!("color: red; font-size: 10rem;")?;

style.insert("font-weight", "bold");
source

pub fn insert_checked<V: Into<String>>( &mut self, key: &str, value: V, ) -> Result<(), WasmCssError>

Insert a new CSS line into Style, retuning an error on invalid key


Example Usage:


let mut style = style!("color: red; font-size: 10rem;")?;

style.insert_checked("font-weight", "bold")?;
source

pub fn remove(&mut self, key: &str) -> Result<(), WasmCssError>

Remove a CSS line from Style


Example Usage:


let mut style = style!("color: red; font-size: 10rem;")?;

style.remove("color", "red")?;
source

pub fn insert_many<V: Into<String>>( &mut self, components: Vec<(&str, V)>, ) -> Result<(), WasmCssError>

Insert many CSS lines into the Style

  • Skips invalid keys

Example Usage:


let mut style = style!("color: red; font-size: 10rem;")?;

style.insert_many(vec![
    ("font-weight", "bold"),
    ("background-color", "red")
])?;
source

pub fn insert_many_checked<V: Into<String>>( &mut self, components: Vec<(&str, V)>, ) -> Result<(), WasmCssError>

Insert many CSS lines into the Style, retuning an error on invalid key


Example Usage:


let mut style = style!("color: red; font-size: 10rem;")?;

style.insert_many(vec![
    ("font-weight", "bold"),
    ("background-color", "red")
])?;
source

pub fn remove_many(&mut self, keys: Vec<&str>) -> Result<(), WasmCssError>

Remove CSS lines from Style


Example Usage:


let mut style = style!("color: red; font-size: 10rem;")?;

style.remove("color", "red")?;

Trait Implementations§

source§

impl Clone for Style

source§

fn clone(&self) -> Style

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
source§

impl Debug for Style

source§

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

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl Freeze for Style

§

impl RefUnwindSafe for Style

§

impl Send for Style

§

impl Sync for Style

§

impl Unpin 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> CloneToUninit for T
where T: Clone,

source§

unsafe fn clone_to_uninit(&self, dst: *mut T)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dst. 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.