1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
//! Parse and serialize [TOML](https://toml.io/en/v1.1.0) compatible with
//! deser.
//!
//! ```rust
//! use deser::{Deserialize, Serialize};
//!
//! #[derive(Deserialize, Serialize, Debug)]
//! struct Config {
//! name: String,
//! ports: Vec<u16>,
//! }
//!
//! let config: Config = deser_toml::from_str(r#"
//! name = "web"
//! ports = [80, 443]
//! "#).unwrap();
//! assert_eq!(config.name, "web");
//! assert_eq!(config.ports, [80, 443]);
//!
//! let toml = deser_toml::to_string(&config).unwrap();
//! assert_eq!(toml, "name = \"web\"\nports = [80, 443]\n");
//! ```
//!
//! # Data Model
//!
//! The parser implements TOML 1.1 and passes the
//! [toml-test](https://github.com/toml-lang/toml-test) suite. TOML maps
//! onto the deser data model as follows:
//!
//! | TOML | deser |
//! |---------------------------------------|-----------------------------------------|
//! | tables (including the document) | maps |
//! | arrays (including arrays of tables) | sequences |
//! | strings | `Str` |
//! | integers | `U64`, `I64` |
//! | floats | `F64` |
//! | booleans | `Bool` |
//! | date-times, dates and times | [`Datetime`] |
//!
//! Date-times are passed through deser as the well-known
//! [`Datetime`] extension type which falls back to a
//! string for types that do not know it. With the respective features of
//! deser, the date and time types of `jiff`, `chrono` and `time` can be
//! used directly (this example requires the `jiff` feature of deser):
//!
//! ```rust
//! use deser::{Deserialize, Serialize};
//!
//! #[derive(Deserialize, Serialize)]
//! struct Event {
//! start: jiff::Timestamp,
//! day: jiff::civil::Date,
//! }
//!
//! let event: Event = deser_toml::from_str("
//! start = 2024-06-19 15:22:45-04:00
//! day = 2024-06-19
//! ").unwrap();
//! assert_eq!(event.start.to_string(), "2024-06-19T19:22:45Z");
//!
//! let toml = deser_toml::to_string(&event).unwrap();
//! assert_eq!(toml, "start = 2024-06-19T19:22:45Z\nday = 2024-06-19\n");
//! ```
//!
//! The document is always a table. Keys are emitted in the order in which
//! they are defined in the document.
//!
//! Integers are supported in the range of `i64` and `u64`, integers that
//! do not fit are an error. Floats that overflow to infinity are an error
//! as well. Newlines in multi-line strings are normalized to `\n`. A
//! UTF-8 byte order mark at the start of the document is ignored.
//!
//! When serializing, maps are written as tables and sequences of maps as
//! arrays of tables. The well-known [`Timestamp`](deser_core::ext::Timestamp)
//! type is written as offset date-time in UTC, other well-known types
//! (such as UUIDs and decimals) are written as strings. Floats are
//! written with the shortest text that reads back as the same value of
//! their precision (`0.1f32` as `0.1`). TOML has no null value: map
//! entries with null values
//! are skipped and null values in sequences are an error. TOML has no
//! bytes either, they are written as base64 strings by default (see
//! [bytes](deser_core::adapters#bytes)). See [`SerializerConfig`] for more
//! information.
//!
//! # Streams
//!
//! Documents are read from a [`Read`](std::io::Read) with [`from_reader`]
//! and written to a [`Write`](std::io::Write) with [`to_writer`]. The
//! configurations also create readers and writers of
//! [`deser::io`](deser_core::io) ([`DeserializerConfig::reader`] and
//! [`SerializerConfig::writer`]), the stream serializer ([`Serializer`])
//! and deserializer ([`StreamDeserializer`]) work with other kinds of IO
//! too (for instance async runtimes with `deser-tokio`). As TOML
//! documents cannot be split, the whole document is read before it's
//! parsed.
//!
//! # Features
//!
//! * `io` (enabled by default): reading and writing streams of the
//! standard library, see [streams](#streams).
//! * `speedups` (enabled by default): validates UTF-8 with
//! [`simdutf8`](https://docs.rs/simdutf8).
// `copy.rs` is shared with other formats which only need `alloc`
extern crate alloc;
pub use ;
pub use to_writer;
pub use ;
pub use StreamDeserializer;
pub use from_reader;
/// Re-exported from [`deser::ext`](deser_core::ext) for convenience.
pub use ;