Expand description
bem is a Rust crate that provides a simple and intuitive interface to work with BEM (Block Element Modifier) notation.
It includes functions to parse BEM blocks, elements, and their modifiers, and to convert them to and from JSON representation.
With this crate, you can easily serialize and deserialize BEM structures in your Rust applications, making it an excellent choice for web developers, CSS authors, and anyone working with BEM-based design.
§Features
- Parse BEM Notation: Use the
parsefunction to interpret BEM strings and create corresponding Rust structures. - JSON Serialization and Deserialization: Convert BEM blocks to JSON strings and vice versa with the
to_jsonandfrom_jsonfunctions. - Customizable Models: Work with
BEMBlockandBEMElementstructs to represent BEM structures, supporting custom modifiers and elements.
§Quick Start
Add the crate to your Cargo.toml and start working with BEM structures right away!
use bem::{BEMBlock, to_json, from_json};
let bem_block = BEMBlock { name: "media-player".to_string(), modifiers: vec![], elements: vec![] };
let json = to_json(&bem_block).unwrap();
let bem_block_from_json = from_json(&json).unwrap();Please see the individual function and structure documentation for detailed information and examples.
Structs§
- BEMBlock
- Represents a BEM (Block Element Modifier) block, which consists of a name, a list of modifiers, and a list of elements.
- BEMElement
- Represents an element within a BEM block, with its own name and list of modifiers.
Functions§
- from_
json - Converts a JSON string into a
BEMBlock. - parse
- Parses a BEM (Block, Element, Modifier) syntax string into a structured representation.
- to_json
- Converts a
BEMBlockinto a JSON string. - to_
json_ pretty - Converts a
BEMBlockinto a pretty-printed JSON string.