Expand description
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
dumpproduces full serialization wrapped in ado ... return _ endblock with a self-reference section. Compact and sparse by default.- [
line] produces single-line output. It is an expression, so prependreturnto evaluate it. blockproduces multi-line indented output. Also an expression.- [
serialize] is the raw entry point with no default options. - [
load] parses serialized output back into aValue.
§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(_)));Re-exports§
pub use load::load;pub use load::LoadError;pub use load::LoadOptions;pub use options::Options;pub use serialize::serialize;pub use serialize::SerError;pub use value::Func;pub use value::Global;pub use value::Ident;pub use value::Key;pub use value::MetaError;pub use value::MetaFn;pub use value::Table;pub use value::TableData;pub use value::Value;
Modules§
- load
- The deserializer.
- numfmt
- C
printfnumber formatting for%gand%econversions. - options
- Serialization options.
- quote
- Lua string-literal escaping.
- serialize
- The serializer core.
- value
- The Lua value model.
Constants§
- COPYRIGHT
- Copyright holder, matching serpent’s
_COPYRIGHT. - DESCRIPTION
- Description, matching serpent’s
_DESCRIPTION. - NAME
- Module name, matching serpent’s
_NAME. - VERSION
- Version string, matching serpent’s
_VERSION.
Functions§
- block
- Multi-line indented pretty printing. Two-space
indent,sortkeys,commenton. - block_
with - Multi-line pretty printing with caller options. Build the options over
Options::block, then override the fields you need. - dump
- Full serialization:
name = "_", compact, sparse. - dump_
with - Full serialization with extra options merged over the
dumpdefaults. - line
- Single-line pretty printing.
sortkeysandcommenton. - line_
with - Single-line pretty printing with caller options. Build the options over
Options::line, then override the fields you need.