Skip to main content

Crate maml

Crate maml 

Source
Expand description

A parser and serializer for MAML (Minimal Abstract Markup Language) — a minimal, human-readable data format.

§Quick start

use maml::{parse, stringify, Value};

// Parse a MAML string into a Value
let value = parse(r#"{name: "maml", version: 1}"#).unwrap();
assert_eq!(value["name"], Value::String("maml".into()));

// Serialize a Value back to a MAML string
let output = stringify(&value).unwrap();
assert_eq!(output, "{\n  name: \"maml\"\n  version: 1\n}");

§Serde support

With the serde feature (enabled by default), you can serialize and deserialize any type that implements Serialize/Deserialize:

use serde::{Serialize, Deserialize};

#[derive(Serialize, Deserialize, PartialEq, Debug)]
struct Config {
    name: String,
    port: u16,
    debug: bool,
}

let config = Config { name: "app".into(), port: 8080, debug: false };

// Serialize to MAML
let s = maml::to_string(&config).unwrap();

// Deserialize from MAML
let back: Config = maml::from_str(&s).unwrap();
assert_eq!(config, back);

To use this crate without serde, disable default features:

[dependencies]
maml = { version = "0.1", default-features = false }

§MAML format

{
  # Comments start with hash
  key: "quoted string"
  identifier_key: 42

  array: [
    "comma or newline separated"
    true
    null
    3.14
  ]

  raw_string: """
No escaping needed here.
Preserves \n and "quotes" as-is.
"""
}

See the full specification at https://maml.dev.

Structs§

Error
Error type for MAML parsing and serialization.

Enums§

Value
Represents a MAML value.

Functions§

from_str
Deserializes a MAML string into any type that implements Deserialize.
from_value
Deserializes a Value into any type that implements Deserialize.
parse
Parses a MAML string into a Value.
stringify
Serializes a Value into a pretty-printed MAML string.
to_string
Serializes any type that implements Serialize into a MAML string.