CssVar

Struct CssVar 

Source
pub struct CssVar(/* private fields */);
Expand description

Represents a reference to a CSS custom property (CSS variable).

The CssVar struct allows you to reference CSS variables in your styles. When displayed, it formats the variable name as var(--name), which is the correct syntax for using CSS variables in property values.

CSS variables provide a way to store values that can be reused throughout a document. They help maintain consistency and make it easier to update styles globally.

§Examples

use mew_css::variable::{CssVar, var};
use mew_css::style;
use mew_css::values::Color;

// Create a CSS variable reference
let primary_color = CssVar::new("primary-color");

// Use it in a style
let css = style()
    .color(Color::Var(primary_color))
    .apply();

assert_eq!(css, "color: var(--primary-color);");

// The shorter way using the `var` function and `into()`
let css = style()
    .color(var("primary-color").into())
    .apply();

assert_eq!(css, "color: var(--primary-color);");

Implementations§

Source§

impl CssVar

Source

pub fn new(name: &str) -> Self

Creates a new CSS variable reference.

This method creates a reference to a CSS variable that can be used in property values. The variable name can be provided with or without the -- prefix; if it’s missing, it will be added automatically.

§Arguments
  • name - The variable name (with or without the -- prefix)
§Returns

A new CssVar instance

§Examples
use mew_css::variable::CssVar;

// These are equivalent
let var1 = CssVar::new("primary-color");
let var2 = CssVar::new("--primary-color");

Trait Implementations§

Source§

impl Clone for CssVar

Source§

fn clone(&self) -> CssVar

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 CssVar

Source§

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

Formats the value using the given formatter. Read more
Source§

impl Display for CssVar

Source§

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

Formats the value using the given formatter. Read more
Source§

impl From<CssVar> for AlignItems

Source§

fn from(var: CssVar) -> Self

Converts to this type from the input type.
Source§

impl From<CssVar> for BorderStyle

Source§

fn from(var: CssVar) -> Self

Converts to this type from the input type.
Source§

impl From<CssVar> for Color

Source§

fn from(var: CssVar) -> Self

Converts to this type from the input type.
Source§

impl From<CssVar> for Cursor

Source§

fn from(var: CssVar) -> Self

Converts to this type from the input type.
Source§

impl From<CssVar> for Display

Source§

fn from(var: CssVar) -> Self

Converts to this type from the input type.
Source§

impl From<CssVar> for FlexDirection

Source§

fn from(var: CssVar) -> Self

Converts to this type from the input type.
Source§

impl From<CssVar> for FontSize

Source§

fn from(var: CssVar) -> Self

Converts to this type from the input type.
Source§

impl From<CssVar> for FontWeight

Source§

fn from(var: CssVar) -> Self

Converts to this type from the input type.
Source§

impl From<CssVar> for JustifyContent

Source§

fn from(var: CssVar) -> Self

Converts to this type from the input type.
Source§

impl From<CssVar> for LineHeight

Source§

fn from(var: CssVar) -> Self

Converts to this type from the input type.
Source§

impl From<CssVar> for Overflow

Source§

fn from(var: CssVar) -> Self

Converts to this type from the input type.
Source§

impl From<CssVar> for Position

Source§

fn from(var: CssVar) -> Self

Converts to this type from the input type.
Source§

impl From<CssVar> for Size

Source§

fn from(var: CssVar) -> Self

Converts to this type from the input type.
Source§

impl From<CssVar> for TextAlign

Source§

fn from(var: CssVar) -> Self

Converts to this type from the input type.
Source§

impl From<CssVar> for TextDecoration

Source§

fn from(var: CssVar) -> Self

Converts to this type from the input type.
Source§

impl From<CssVar> for Visibility

Source§

fn from(var: CssVar) -> Self

Converts to this type from the input type.
Source§

impl From<CssVar> for ZIndex

Source§

fn from(var: CssVar) -> Self

Converts to this type from the input type.
Source§

impl PartialEq for CssVar

Source§

fn eq(&self, other: &CssVar) -> 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 CssVar

Auto Trait Implementations§

§

impl Freeze for CssVar

§

impl RefUnwindSafe for CssVar

§

impl Send for CssVar

§

impl Sync for CssVar

§

impl Unpin for CssVar

§

impl UnwindSafe for CssVar

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> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. 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.