tomling
tomling is a simple TOML parser API, that is designed to have minimal dependencies and is no_std
compatible. The main target is Cargo manifests (Cargo.toml files) and hence why specific
API is provided for that purpose as well.
Usage
use ;
//
// Using the `Cargo.toml` specific API:
//
let manifest: Manifest = from_str.unwrap;
assert_eq!;
assert_eq!;
assert_eq!;
assert_eq!;
let authors = manifest.package.authors.unwrap;
let alice = &authors;
assert_eq!;
assert_eq!;
let bob = &authors;
assert_eq!;
assert_eq!;
let serde = match manifest.dependencies.unwrap.by_name.unwrap ;
assert_eq!;
assert_eq!;
let regex = match manifest.dependencies.unwrap.by_name.unwrap ;
assert_eq!;
let cc = match manifest
.targets
.unwrap
.by_name
.unwrap
.build_dependencies
.unwrap
.by_name
.unwrap
;
assert_eq!;
let default = manifest.features.unwrap.by_name.unwrap;
assert_eq!;
let binary = &manifest.binaries.unwrap;
assert_eq!;
assert_eq!;
//
// Using the generic raw `TOML` parsing API:
//
let manifest = parse.unwrap;
let package = match manifest.get.unwrap ;
assert_eq!;
assert_eq!;
assert_eq!;
assert_eq!;
let deps = match manifest.get.unwrap ;
let serde = match deps.get.unwrap ;
assert_eq!;
let serde_features = match serde.get.unwrap ;
assert_eq!;
let regex = match deps.get.unwrap ;
assert_eq!;
const CARGO_TOML: &'static str = r#"
[package]
name = "example"
version = "0.1.0"
edition = "2021"
authors = ["Alice Great <foo@bar.com>", "Bob Less"]
resolver = "2"
[dependencies]
serde = { version = "1.0", features = [
"std",
"derive", # and here.
] }
regex = "1.5"
[target.'cfg(unix)'.build-dependencies]
cc = "1.0.3"
[features]
default = ["serde"]
[[bin]]
name = "some-binary"
path = "src/bin/my-binary.rs"
"#;
Dependencies
winnowwithallocandsimdfeatures enabled.serde(optional) withallocandderivefeatures enabled.
Features
serde- Enables Serde support.cargo-toml- Enables Cargo manifest specific API. This requiresserde.simd- Enables thesimdfeature ofwinnowfor SIMD acceleration for parsing.std- Enables some features, likestd::error::Errorimplementation forErrortype. It also enablesstdfeature ofwinnowandserde.
All features are enabled by default.
Comparison with toml crate
The toml crate is great but it being based on toml-edit, it ends up requiring indexmap crate
and its dependencies. tomling was created specifically to avoid most of these dependencies by
focusing completely on the parsing of TOML documents only.
Goals
- Simple parser/deserializer API.
- Minimum dependencies. The only mandatory dependency is
winnowwith only 2 features enabled. - Primary target: Cargo manifests.
Non-goals
- Strict compliance with the specification. This can change if sufficient demand arises. 😉
- Encoder/Serializer API.
License
The Name
The name "tomling" is a portmanteau of "TOML" and "ling" (a suffix meaning "a small thing"). Coincidentally, it also means a "male kitten" in English, with all the stress on the "kitten" part 😸 and none on the "male" part.