Layers

Struct Layers 

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

Configuration for the Config::layers field.

It defines a list of layers used to change the ordering of the generated classes.

§Layers and ordering

By default, every class is ordered based on its plugin, variants and modifier.

If you want more control over the ordering of a specific set of classes, you can define a layer in the configuration (see the example below) and use the variant l-<layer_name> to put the class in the corresponding layer.

By default, the layer containing builtin plugins has the index 0 and the layer containing custom plugins has index -1.

The index is an i8, so it’s between -128 and 127.

§Example

use encre_css::Config;

let mut config = Config::default();
config.layers.add("components", -2);
config.layers.add("utilities", 2);

let generated = encre_css::generate(
    [r#"<button class="l-components:bg-red-500 l-utilities:bg-red-100">Click me</button>"#],
    &config,
);

// Without the use of layers, `bg-red-100` would have been generated first and would have been
// overridden by `bg-red-500`.
// Here the layer `components` has an index smaller than the layer
// `utilities`, so all the classes on this layer will be generated first.
assert!(generated.ends_with(r#".l-components\:bg-red-500 {
  background-color: oklch(63.7% .237 25.331);
}

.l-utilities\:bg-red-100 {
  background-color: oklch(93.6% .032 17.717);
}"#));

§Corresponding TOML configuration

[layers]
components = -2
utilities = 2

Implementations§

Source§

impl Layers

Source

pub fn add<T1: Into<Cow<'static, str>>>(&mut self, key: T1, val: i8)

Add a layer to the list.

Source

pub fn remove<T: Into<Cow<'static, str>>>(&mut self, key: T)

Remove a layer from the list.

Trait Implementations§

Source§

impl Clone for Layers

Source§

fn clone(&self) -> Layers

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 Layers

Source§

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

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

impl Default for Layers

Source§

fn default() -> Layers

Returns the “default value” for a type. Read more
Source§

impl<'de> Deserialize<'de> for Layers

Source§

fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl PartialEq for Layers

Source§

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

Source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more
Source§

impl Eq for Layers

Source§

impl StructuralPartialEq for Layers

Auto Trait Implementations§

§

impl Freeze for Layers

§

impl RefUnwindSafe for Layers

§

impl Send for Layers

§

impl Sync for Layers

§

impl Unpin for Layers

§

impl UnwindSafe for Layers

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.
Source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,