12 stable releases

2.13.0 Mar 28, 2024
2.12.0 Mar 27, 2024
2.11.1 Jan 31, 2024
2.10.2 Oct 19, 2023
2.9.2 Sep 30, 2023

#2310 in Encoding

Download history 54/week @ 2024-03-11 19/week @ 2024-03-18 442/week @ 2024-03-25 60/week @ 2024-04-01 27/week @ 2024-04-08 19/week @ 2024-04-15 28/week @ 2024-04-22 16/week @ 2024-04-29 13/week @ 2024-05-06 8/week @ 2024-05-13 21/week @ 2024-05-20 55/week @ 2024-05-27 60/week @ 2024-06-03 278/week @ 2024-06-10 22/week @ 2024-06-17 55/week @ 2024-06-24

419 downloads per month
Used in 3 crates (via sval_derive)

Apache-2.0 OR MIT

325KB
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

~90KB