1//! [![github]](https://github.com/dtolnay/basic-toml) [![crates-io]](https://crates.io/crates/basic-toml) [![docs-rs]](https://docs.rs/basic-toml)
2//!
3//! [github]: https://img.shields.io/badge/github-8da0cb?style=for-the-badge&labelColor=555555&logo=github
4//! [crates-io]: https://img.shields.io/badge/crates.io-fc8d62?style=for-the-badge&labelColor=555555&logo=rust
5//! [docs-rs]: https://img.shields.io/badge/docs.rs-66c2a5?style=for-the-badge&labelColor=555555&logo=docs.rs
6//!
7//! <br>
8//!
9//! A library for parsing and producing data in [TOML] format using [Serde].
10//!
11//! TOML is designed to be "a config file format for humans": minimal and easy
12//! to read due to obvious semantics.
13//!
14//! ```toml
15//! [package]
16//! name = "basic-toml"
17#![doc = concat!("version = \"", env!("CARGO_PKG_VERSION_MAJOR"), ".", env!("CARGO_PKG_VERSION_MINOR"), ".", env!("CARGO_PKG_VERSION_PATCH"), "\"")]
18//! authors = ["Alex Crichton <alex@alexcrichton.com>"]
19//!
20//! [dependencies]
21//! serde = "1.0"
22//! ```
23//!
24//! The TOML format is widely used throughout the Rust community for
25//! configuration, notably being used by [Cargo], Rust's package manager.
26//!
27//! [TOML]: https://toml.io
28//! [Serde]: https://serde.rs
29//! [Cargo]: https://crates.io
30//!
31//! # Deserialization
32//!
33//! ```
34//! use semver::{Version, VersionReq};
35//! use serde_derive::Deserialize;
36//! use std::collections::BTreeMap as Map;
37//!
38//! #[derive(Deserialize)]
39//! struct Manifest {
40//! package: Package,
41//! #[serde(default)]
42//! dependencies: Map<String, VersionReq>,
43//! }
44//!
45//! #[derive(Deserialize)]
46//! struct Package {
47//! name: String,
48//! version: Version,
49//! #[serde(default)]
50//! authors: Vec<String>,
51//! }
52//!
53//! fn main() {
54//! let manifest: Manifest = basic_toml::from_str(r#"
55//! [package]
56//! name = "basic-toml"
57#![doc = concat!(" version = \"", env!("CARGO_PKG_VERSION_MAJOR"), ".", env!("CARGO_PKG_VERSION_MINOR"), ".", env!("CARGO_PKG_VERSION_PATCH"), "\"")]
58//! authors = ["Alex Crichton <alex@alexcrichton.com>"]
59//!
60//! [dependencies]
61//! serde = "^1.0"
62//! "#).unwrap();
63//!
64//! assert_eq!(manifest.package.name, "basic-toml");
65#![doc = concat!(" assert_eq!(manifest.package.version, Version::new(", env!("CARGO_PKG_VERSION_MAJOR"), ", ", env!("CARGO_PKG_VERSION_MINOR"), ", ", env!("CARGO_PKG_VERSION_PATCH"), "));")]
66//! assert_eq!(manifest.package.authors, ["Alex Crichton <alex@alexcrichton.com>"]);
67//! assert_eq!(manifest.dependencies["serde"].to_string(), "^1.0");
68//! }
69//! ```
70//!
71//! # Serialization
72//!
73//! ```
74//! use semver::{Version, VersionReq};
75//! use serde_derive::Serialize;
76//! use std::collections::BTreeMap as Map;
77//!
78//! #[derive(Serialize)]
79//! struct Manifest {
80//! package: Package,
81//! dependencies: Map<String, VersionReq>,
82//! }
83//!
84//! #[derive(Serialize)]
85//! struct Package {
86//! name: String,
87//! version: Version,
88//! authors: Vec<String>,
89//! }
90//!
91//! fn main() {
92//! let manifest = Manifest {
93//! package: Package {
94//! name: "basic-toml".to_owned(),
95#![doc = concat!(" version: Version::new(", env!("CARGO_PKG_VERSION_MAJOR"), ", ", env!("CARGO_PKG_VERSION_MINOR"), ", ", env!("CARGO_PKG_VERSION_PATCH"), "),")]
96//! authors: vec!["Alex Crichton <alex@alexcrichton.com>".to_owned()],
97//! },
98//! dependencies: {
99//! let mut dependencies = Map::new();
100//! dependencies.insert("serde".to_owned(), "^1.0".parse().unwrap());
101//! dependencies
102//! },
103//! };
104//!
105//! let toml = basic_toml::to_string(&manifest).unwrap();
106//! print!("{}", toml);
107//! }
108//! ```
109//!
110//! # Spec compatibility
111//!
112//! TOML v0.5.0.
113//!
114//! TOML's date and time syntax are not supported.
115
116#![doc(html_root_url = "https://docs.rs/basic-toml/0.1.2")]
117#![deny(missing_docs)]
118#![allow(
119 clippy::bool_to_int_with_if,
120 clippy::let_underscore_untyped,
121 clippy::manual_let_else,
122 clippy::manual_range_contains,
123 clippy::match_like_matches_macro,
124 clippy::missing_errors_doc,
125 clippy::must_use_candidate,
126 clippy::needless_doctest_main,
127 clippy::needless_pass_by_value,
128 clippy::similar_names,
129 clippy::type_complexity,
130 clippy::uninlined_format_args,
131 clippy::unwrap_or_else_default
132)]
133
134mod de;
135mod error;
136mod ser;
137mod tokens;
138
139pub use crate::de::{from_slice, from_str};
140pub use crate::error::Error;
141pub use crate::ser::to_string;
142