pub struct Style { /* private fields */ }Expand description
Represents a CSS Style
Implementations§
source§impl Style
impl Style
sourcepub fn new(css: String, class: Option<String>) -> Result<Self, WasmCssError>
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
WasmCssErrorif unable to locate Crypto when generating uuid for class name -
Filters out invalid CSS keys, use
Style::new_checkedif you would like to handle invalid CSS
Example Usage:
let style: Style = Style::new(
"
gap: 10rem;
display: flex;
flex-direction: column;
",
None,
)?;sourcepub fn new_checked(
css: String,
class: Option<String>,
) -> Result<Self, WasmCssError>
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
WasmCssErrorif 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,
);sourcepub fn append(&mut self, source: &Style) -> Result<(), WasmCssError>
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;"sourcepub fn insert<V: Into<String>>(
&mut self,
key: &str,
value: V,
) -> Result<(), WasmCssError>
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");sourcepub fn insert_checked<V: Into<String>>(
&mut self,
key: &str,
value: V,
) -> Result<(), WasmCssError>
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")?;sourcepub fn remove(&mut self, key: &str) -> Result<(), WasmCssError>
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")?;sourcepub fn insert_many<V: Into<String>>(
&mut self,
components: Vec<(&str, V)>,
) -> Result<(), WasmCssError>
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")
])?;sourcepub fn insert_many_checked<V: Into<String>>(
&mut self,
components: Vec<(&str, V)>,
) -> Result<(), WasmCssError>
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")
])?;sourcepub fn remove_many(&mut self, keys: Vec<&str>) -> Result<(), WasmCssError>
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§
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> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
source§unsafe fn clone_to_uninit(&self, dst: *mut T)
unsafe fn clone_to_uninit(&self, dst: *mut T)
clone_to_uninit)