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
128
129
130
131
132
133
134
135
136
//! Serialize Lua values to round-trippable Lua source.
//!
//! This crate turns a [`Value`] graph into Lua source code that Lua's `load`
//! reads back into an equivalent value graph. It is both a serializer and a
//! pretty printer. It preserves shared references, reconstructs cyclic
//! references, and emits arrays positionally, string keys in short notation, and
//! the special numbers as `1/0`, `-1/0`, `0/0`.
//!
//! # Entry points
//!
//! - [`dump`] produces full serialization wrapped in a `do ... return _ end`
//! block with a self-reference section. Compact and sparse by default.
//! - [`line`] produces single-line output. It is an expression, so prepend
//! `return ` to evaluate it.
//! - [`block`] produces multi-line indented output. Also an expression.
//! - [`serialize`] is the raw entry point with no default options.
//! - [`load`] parses serialized output back into a [`Value`].
//!
//! # Example
//!
//! ```
//! use serpent_serializer::{line, load, LoadOptions};
//! use serpent_serializer::value::{Table, Key, Value};
//!
//! let t = Table::new();
//! t.push(Value::Str(b"a".to_vec()));
//! t.push(Value::Str(b"b".to_vec()));
//! t.set(Key::Str(b"x".to_vec()), Value::Number(1.0));
//!
//! let src = line(&Value::Table(t)).unwrap();
//! let back = load(&src, &LoadOptions::default()).unwrap();
//! assert!(matches!(back, Value::Table(_)));
//! ```
pub use ;
pub use Options;
pub use ;
pub use ;
/// Module name, matching serpent's `_NAME`.
pub const NAME: &str = "serpent";
/// Copyright holder, matching serpent's `_COPYRIGHT`.
pub const COPYRIGHT: &str = "Paul Kulchenko";
/// Description, matching serpent's `_DESCRIPTION`.
pub const DESCRIPTION: &str = "Lua serializer and pretty printer";
/// Version string, matching serpent's `_VERSION`.
pub const VERSION: &str = "0.303";
/// Full serialization: `name = "_"`, compact, sparse.
///
/// Output is a `do ... return _ end` block that returns the value when loaded.
///
/// # Errors
///
/// Propagates [`SerError`] from [`serialize`].
/// Full serialization with extra options merged over the `dump` defaults.
///
/// # Errors
///
/// Propagates [`SerError`] from [`serialize`].
///
/// # Example
///
/// Build options over the `dump` defaults, then override what you need.
///
/// ```
/// use serpent_serializer::{dump_with, Options};
/// use serpent_serializer::value::{Table, Value};
///
/// let t = Table::new();
/// t.push(Value::Number(1.0));
/// let opts = Options { maxnum: Some(1), ..Options::dump() };
/// let src = dump_with(&Value::Table(t), opts).unwrap();
/// assert_eq!(src, "do local _={1};return _;end");
/// ```
/// Single-line pretty printing. `sortkeys` and `comment` on.
///
/// Output is an expression. Prepend `return ` to evaluate it, which [`load`]
/// does automatically.
///
/// # Errors
///
/// Propagates [`SerError`] from [`serialize`].
/// Single-line pretty printing with caller options. Build the options over
/// [`Options::line`], then override the fields you need.
///
/// # Errors
///
/// Propagates [`SerError`] from [`serialize`].
/// Multi-line indented pretty printing. Two-space `indent`, `sortkeys`,
/// `comment` on.
///
/// Output is an expression. Prepend `return ` to evaluate it.
///
/// # Errors
///
/// Propagates [`SerError`] from [`serialize`].
/// Multi-line pretty printing with caller options. Build the options over
/// [`Options::block`], then override the fields you need.
///
/// # Errors
///
/// Propagates [`SerError`] from [`serialize`].