pub struct Scanner { /* private fields */ }
Expand description
A structure responsible for scanning some content and returning a list of possible classes.
By default, it splits the content by spaces, double quotes, single quotes, backticks and new
lines, while ignoring arbitrary the content inside values/variants and variant groups
by using split_ignore_arbitrary
.
It is recommended to use this function when splitting classes with characters which can be
included inside arbitrary strings.
§Example
The following code snippet defines a scanner for extracting classes listed in the data-en
HTML attribute.
use encre_css::{Config, Scanner};
use std::collections::BTreeSet;
let mut config = Config::default();
config.scanner = Scanner::from_fn(|content| content.split(r#"data-en=""#)
.filter_map(|v| v.split_once("\"").map(|(classes, _)| classes.split_whitespace()))
.flatten()
.collect::<BTreeSet<&str>>());
let generated = encre_css::generate(
[r#"<h1 data-en="underline"></h1><p data-en="bg-red-200 text-blue-300"></p>"#],
&config,
);
assert!(generated.ends_with(".bg-red-200 {
background-color: oklch(88.5% .062 18.334);
}
.text-blue-300 {
color: oklch(80.9% .105 251.813);
}
.underline {
-webkit-text-decoration-line: underline;
text-decoration-line: underline;
}"));
Implementations§
Trait Implementations§
Auto Trait Implementations§
impl Freeze for Scanner
impl !RefUnwindSafe for Scanner
impl Send for Scanner
impl Sync for Scanner
impl Unpin for Scanner
impl !UnwindSafe for Scanner
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
Mutably borrows from an owned value. Read more