Expand description
Structured, streaming values.
sval is a serialization framework that treats data as a flat stream of tokens.
The source of that data could be some Rust object or parsed from some encoding.
It’s well suited to self-describing, text-based formats like JSON.
§Getting started
For a complete introduction, see the project readme.
Add sval to your Cargo.toml:
[dependencies.sval]
version = "2.16.0"By default, sval doesn’t depend on Rust’s standard library or integrate with its collection types.
To include them, add the alloc or std Cargo features:
[dependencies.sval]
version = "2.16.0"
features = ["std"]sval provides procedural macros for deriving its traits.
Add the derive Cargo feature to enable them:
[dependencies.sval]
version = "2.16.0"
features = ["derive"]§The Value trait
Value is a trait for data types to implement that surfaces their structure through visitors called streams.
Value is like serde’s Serialize. It can also be used like serde’s Deserialize.
Many standard types in Rust implement the Value trait. It can be derived on your own types using the sval_derive library.
§The Stream trait
Stream is a trait for data formats and visitors to implement that observes the structure of values.
Stream is like serde’s Serializer. It can also be used like serde’s Deserializer.
§Data-model
sval’s data-model is defined by the Stream trait. It includes:
- Null
- Booleans (true,false)
- Text blobs
- Binary blobs
- Integers (u8-u128,i8-i128)
- Binary floating points (f32-f64)
- Sequences
- Maps
- Tags
- Tagged values
- Records
- Tuples
- Enums
§Tags
Tag is a type for extending sval’s data-model with new kinds of values.
Rust’s own () and Option<T> types are expressed as tags.
Other examples of tags include text that encodes RFC3339 timestamps or RFC4122 UUIDs.
The tags module contains built-in tags.
Other libraries may define their own tags too.
Modules§
- default_stream 
- Default method implementations for Streams.
- default_value 
- Default method implementations for Values.
- tags
- Built-in tags for fundamental types.
Structs§
- BinaryArray 
- An adapter that streams a slice of 8bit unsigned integers as binary with a fixed size.
- BinarySlice 
- An adapter that streams a slice of 8bit unsigned integers as binary.
- Display
- Adapt a fmt::Displayinto an [sval::Value].
- Error
- An error encountered while streaming a value.
- Index
- The index of a value in its parent context.
- Label
- A textual label for some value.
- MapSlice
- An adapter that streams a slice of key-value pairs as a map.
- Null
- The absence of any meaningful value.
- Tag
- A type tag for a value.
Traits§
Functions§
- error
- A streaming result with a generic failure.
- stream
- Stream a value through a stream.
- stream_computed 
- Stream a value through a stream with an arbitrarily short lifetime.
- stream_display 
- Stream a fmt::Displayas text into aStream.
- stream_display_ fragments 
- Stream a fmt::Displayas text fragments into aStream, without callingStream::text_beginorStream::text_end.
- stream_number 
- Stream an arbitrary precision number conforming to tags::NUMBERusing itsfmt::Displayimplementation.
Type Aliases§
- Result
- A generic streaming result.