16 stable releases

new 2.14.1 Mar 24, 2025
2.14.0 Jan 14, 2025
2.13.2 Oct 15, 2024
2.13.1 Sep 14, 2024
2.9.2 Sep 30, 2023

#2371 in Encoding

Download history 226/week @ 2024-12-01 350/week @ 2024-12-08 263/week @ 2024-12-15 5/week @ 2024-12-22 195/week @ 2024-12-29 659/week @ 2025-01-05 450/week @ 2025-01-12 362/week @ 2025-01-19 308/week @ 2025-01-26 335/week @ 2025-02-02 336/week @ 2025-02-09 207/week @ 2025-02-16 384/week @ 2025-02-23 267/week @ 2025-03-02 606/week @ 2025-03-09 358/week @ 2025-03-16

1,626 downloads per month
Used in 3 crates (via sval_derive)

Apache-2.0 OR MIT

330KB
9K SLoC

sval_flatten

Rust Latest version Documentation Latest

Flatten nested sval::Values onto their parent.


lib.rs:

Flatten nested values when streaming.

This library is like the standard library's Iterator::flatten method, but for sval::Streams. Given a value, it will flatten its nested values onto a parent structure. It supports flattening any combination of map, sequence, record, or tuple onto any other.

If you're using sval_derive, you can use the #[flatten] attribute on a field.

Specifics

Flattening unwraps containers and translates their values into the form needed by their parent. The following types can be flattened:

  • maps
  • sequences
  • records
  • tuples

Any other type, including primitives like tags, booleans, and text will be ignored if flattened.

Maps

  • maps: keys are passed through directly, even if they're complex values like other maps.
  • sequences: keys are the stringified offset of sequence values.
  • records: keys are the label of record values.
  • tuples: keys are the stringified index of tuple values.

Sequences

  • maps: map keys are ignored; only map values are flattened.
  • sequences: sequence values are passed through directly.
  • records: record values are passed through directly.
  • tuples: tuple values are passed through directly.

Records

  • maps: map keys are stringified into labels. For complex values like other maps each nested value is stringified and concatenated together.
  • sequences: labels are the stringified offset of sequence values.
  • records: labels are passed through directly.
  • tuples: labels are the stringified index of tuple values.

Tuples

  • maps: map keys are ignored; only map values are flattened.
  • sequences: indexes are the offset of sequence values.
  • records: indexes are the offset of record values.
  • tuples: tuple values are passed through directly.

Dependencies

~89KB