Struct Style

Source
pub struct Style {
    pub css: String,
    /* private fields */
}
Expand description

Represents a <style> child in the <head> element containing CSS.

css: formatted css String.

Fields§

§css: String

Implementations§

Source§

impl Style

Source

pub fn delete(self) -> Result<(), WasmCssError>

Delete Style, removing it from the DOM.

Returns error if missing access to: Head, Window, Document.


Example Usage:


let mut style = style!("background-color: blue;")?;

style.delete()?;
Source§

impl Style

Source

pub fn extend_from_css(&mut self, new_css: &str) -> Result<(), WasmCssError>

Extend Style with css, re-rendering if new_css is not empty.

Returns error if missing access to: Head, Window, Document.


Example Usage:


let mut style = named_style!(
    "my_style",
    "
        font-size: 10rem;
        background-color: blue;
    "
)?;

style.extend_from_css("font-size: 30rem; display: flex;")?;
Source§

impl Style

Source

pub fn extend_from_style(&mut self, s2: &Style) -> Result<(), WasmCssError>

Extend Style with Style, re-rendering if s2 is not empty.

Returns error if missing access to: Head, Window, Document.


Example Usage:


let mut style1 = named_style!(
    "my_style",
    "
        display: flex;
        flex-direction: row;
    "
)?;


let style2 = style!(
    "
        color: red;
        flex-direction: column;
    "
)?;

style1.extend_from_style(&style2)?;
Source§

impl Style

Source

pub fn remove_keys<K: Into<String>>( &mut self, keys: Vec<K>, ) -> Result<(), WasmCssError>

Remove keys from Style, re-rendering if at-least one key is removed.

Returns error if missing access to: Head, Window, Document.


Example Usage:


let mut style = named_style!(
    "my_style",
    "
        font-size: 18px;

        &:hover {{
            background-color: red;
        }}

        background-color: blue;
    "
)?;

style.remove_keys(vec!["font-size", "&:hover"])?;
Source§

impl Style

Source

pub fn new(css: &str, css_name: Option<&str>) -> Result<Self, WasmCssError>

Create a Style from css, rendering it to the DOM as a <style> in <head>. The css is formatted, minfied, and small errors like invalid semi-colons can be corrected, however invalid CSS itself is not handled by the parser.

Effects remain there order as defined, but their inner fields, as well as the Style’s fields will be ordered in a deterministic fashion to avoid duplication.

Note: Trailing semi-colons are required.

Returns error if missing access to: Head, Crypto(If generating a random ID), Window, Document.

Provide css_name to define a class, ID, or to target a global identifier, E.G.: div, #id, .class.


Example Usage:


let style = Style::new(
    "
        display: flex;

        &:hover {
            background-color: rgba(111, 111, 111, 0.1);
        }

        @media (max-width: 800px) {
            flex-direction: column;
        }
    ",
    Some(".my_class"),
)?;
Source

pub fn identity(&self) -> &str

Returns the identity of the definition inside the <style> element.

Example Usage:


let style = named_style!(".myStyle", "font-size: 5rem;")?;

// "myStyle"
let identity = style.identity();

let style = named_style!("#myStyle", "font-size: 5rem;")?;

// "myStyle"
let identity = style.identity();

let style = named_style!("body", "font-size: 5rem;")?;

// "body"
let identity = style.identity();

Trait Implementations§

Source§

impl Clone for Style

Source§

fn clone(&self) -> Style

Returns a duplicate 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
Source§

impl PartialEq for Style

Source§

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

Tests for self and other values to be equal, and is used by ==.
1.0.0 · 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.
Source§

impl StructuralPartialEq for 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 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, 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.