[−][src]Crate sml
SML
SML
is a simple markup language. It is designed to convert human readable information into
Rust data-structures.
Data Format
- Each line can either be just a key, for example
key:
or it can be a key/value pair, for example
key: "value"
-
Indentation has meaning and is 4 spaces. The first key on the first line determines the alignment of indentation.
-
All values must be double quoted.
-
Every key/value pair must be nested in a key. For example
hobbit: "Frodo"
by itself is invalid. It can be written:
hobbit: name: "Frodo"
Thinking in terms of Rust data-structures, a key without a value represents a struct
or an
enum
while a key/value pair represents a struct
field or enum
variant.
-
Separation of lines has meaning.
-
Keys may not include
:
. -
Double quotes in values must be escaped using
\"
. -
There can be an arbitary amount of whitespace and returns before the first key and after the last key.
-
Characters after the second double-quote in the value are ignored (so this space can be used for comments).
Example
use sml::{Data, Small, SmallError}; #[derive(Debug)] struct Hobbit { name: String, age: u32, friends: Vec<Hobbit>, bicycle: Option<String>, } impl Small for Hobbit { fn from_data(data: Data) -> Result<Self, SmallError> { Ok(Self { name: String::sml(&data, "hobbit::name")?, age: u32::sml(&data, "hobbit::age")?, friends: Vec::<Hobbit>::sml(&data, "hobbit::friends::hobbit")?, bicycle: Option::<String>::sml(&data, "hobbit::bicycle")?, }) } } fn main() { let s = r#" hobbit: name: "Frodo Baggins" age: "98" friends: hobbit: name: "Bilbo Baggins" age: "176" hobbit: name: "Samwise Gamgee" age: "66""#; let frodo = Hobbit::from_str_debug(s); }
Structs
Data |
|
Token | The |
Tokens |
Enums
SmallError | For effective debugging, the function |
Traits
Small | Data-structures that implement the |