| Crates.io | peacock-crest |
| lib.rs | peacock-crest |
| version | 0.1.0 |
| created_at | 2025-01-26 20:23:50.535684+00 |
| updated_at | 2025-01-26 20:23:50.535684+00 |
| description | A CSS library for parsing and applying styles to in-memory DOM structures |
| homepage | |
| repository | https://github.com/nucleus-labs/peacock |
| max_upload_size | |
| id | 1531726 |
| size | 940,317 |
Crest is a Rust library for working with CSS selectors and stylesheets. It provides tools to parse and validate CSS syntax, match selectors against custom DOM-like structures, and apply styles programmatically.
Crest is nearing alpha, and is able to parse any css style rules but unable to parse at-rules. It can also only validate a VERY limited subset of the standard style properties, and some Peacock-specific ones. It's already fairly fast, with planned changes to validation that should make it much faster.
DomElement trait.DomElement trait.DomElement trait.DomElement trait.Crest is not yet available on crates.io. To use it, include it as a dependency using a git repository:
[dependencies]
peacock-crest = { git = "https://github.com/nucleus-labs/Crest/", rev = "<rev>" }
Crest uses Pest to generate parsers for CSS selectors and for the full CSS syntax. Here's how you can parse a selector string:
use peacock_crest::{SourceInfo, SelectorNode};
let selector = "div > .example";
let source_info = SourceInfo::new(selector);
let parsed_selector = SelectorNode::from_source(source_info).expect("Failed to read css");
println!("Parsed selector: {}", parsed_selector);
You can also parse full CSS stylesheets:
use peacock_crest::{SourceInfo, Stylesheet};
let css = "div { color: red; } .example { font-size: 16px; }";
let source_info = SourceInfo::new(css);
let stylesheet = Stylesheet::from_source(source_info).expect("Failed to read css");
println!("Parsed stylesheet:\n{}", stylesheet);
To match a selector against a custom element, implement the DomElement trait for your type:
// todo
Crest currently uses the following to validate Crest's functionality for historical reference and to ensure compatibility with a range of CSS practices:
To run them, use:
cargo test
Performance benchmarks are available in the benches directory. To run them, use:
cargo bench
Current Results: