Skip to main content

ClassPart

Trait ClassPart 

Source
pub trait ClassPart {
    // Required methods
    fn write_to(&self, f: &mut Formatter<'_>) -> Result;
    fn should_skip(&self) -> bool;
}
Expand description

A trait for types that can be used as parts of a CSS class attribute.

This trait enables different types to participate in class merging via the classes! macro. Implementations handle how each type writes its class value and whether it should be skipped.

§Provided Implementations

  • &str: Writes the string directly. Skipped if the string is empty.
  • Option<&str>: Writes the inner string if Some, skipped if None or empty.

§Example

use plait::{html, classes, render};

let base = "btn";
let variant = Some("btn-primary");
let disabled: Option<&str> = None;

let html = render(html! {
    button(class: classes!(base, variant, disabled)) { "Click" }
});

assert_eq!(html, "<button class=\"btn btn-primary\">Click</button>");

Required Methods§

Source

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

Writes this class part to the formatter.

Source

fn should_skip(&self) -> bool

Returns true if this class part should be skipped when merging.

Implementations on Foreign Types§

Source§

impl ClassPart for &str

Source§

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

Source§

fn should_skip(&self) -> bool

Source§

impl ClassPart for Option<&str>

Source§

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

Source§

fn should_skip(&self) -> bool

Implementors§