58 releases (27 stable)

2.13.0 Mar 28, 2024
2.11.1 Jan 31, 2024
2.10.2 Oct 19, 2023
2.6.1 Jun 27, 2023
0.0.4 Dec 6, 2018

#164 in Encoding

Download history 72302/week @ 2024-01-03 78833/week @ 2024-01-10 89543/week @ 2024-01-17 79965/week @ 2024-01-24 78052/week @ 2024-01-31 80444/week @ 2024-02-07 83255/week @ 2024-02-14 99530/week @ 2024-02-21 95300/week @ 2024-02-28 88212/week @ 2024-03-06 85033/week @ 2024-03-13 94507/week @ 2024-03-20 99502/week @ 2024-03-27 111441/week @ 2024-04-03 114701/week @ 2024-04-10 88790/week @ 2024-04-17

431,365 downloads per month
Used in 17 crates (13 directly)

Apache-2.0 OR MIT

120KB
3K SLoC

sval: Streaming, structured values

Rust Latest version Documentation Latest

sval is a lightweight serialization-only framework that treats values like a flat stream of tokens. It's well suited to self-describing text formats like JSON.

How is this different from serde?

serde is the de-facto serialization framework for Rust and is well suited to the majority of use cases. sval is like a light blend of serde::ser and serde::de that is smaller in scope. It makes a few key different design decisions than serde that make it effective for working with self-describing formats:

  1. The API is flat rather than using recursion to stream nested datastructures.
  2. All values with dynamic sizes, including text strings, can be streamed in multiple calls.
  3. Borrowing is an optional optimization.
  4. The core data model is small, with tags for extensibility.

Data-model

  • Values:
    • null: the absence of any other meaningful value.
    • Booleans: true and false.
    • Text strings: stream of UTF8-encoded bytes.
    • Binary strings: stream of arbtirary bytes.
    • Numbers:
      • Integers: u8-u128, i8-i128.
      • Binary floating point: f32-f64.
    • Maps: heterogeneous collection of key-value pairs.
    • Sequences: heterogeneous collection of values.
    • Tags: out-of-band type hints.
    • Tagged values: a tag associated with a value.
    • Records: tagged maps where keys are well-known labels.
    • Tuples: tagged sequences.
    • Enums: tagged variants, where variants are enums, tags, tagged values, records, or tuples.

sval includes built-in tags that extend its data-model with some common datatypes:

  • Rust primitives:
    • ().
    • Option<T>.
  • Arbitrary-precision decimal floating point numbers.

Other built-in tags may be added in the future. Libraries may also define their own tags.

Current status

This project has a complete and stable API, but isn't well documented yet.

Dependencies

~115KB