crosvm/serde_keyvalue
Alexandre Courbot 3573dfef69 serde_keyvalue: add support for sequences and sets
Sequences and sets can be supported by implementing the SeqAccess trait.
This opens up a few new scenarios for the command-line argument parser,
like support for tuples and flags collected into a set.

For instance, the following struct:

    struct Layout {
        resolution: (u16, u16),
        scanlines: Vec<u16>,
    }

Can be built from the following input:

    resolution=[320,200],scanlines=[0,64,128]

BUG=b:248993755
TEST=cargo test -p serde_keyvalue
TEST=cargo test

Change-Id: Ie8972807ed6b171f5b65f6d5b6d458a2cbf450a5
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/3915039
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Commit-Queue: Alexandre Courbot <acourbot@chromium.org>
Reviewed-by: Dennis Kempin <denniskempin@google.com>
2022-10-05 06:57:37 +00:00
..
serde_keyvalue_derive Update all copyright headers to match new style 2022-09-13 18:41:29 +00:00
src serde_keyvalue: add support for sequences and sets 2022-10-05 06:57:37 +00:00
Cargo.toml serde_keyvalue: use nom crate for parsing 2022-08-24 00:37:59 +00:00
README.md

Serde deserializer from key=value strings

A lightweight serde deserializer for strings containing key-value pairs separated by commas, as commonly found in command-line parameters.

Say your program takes a command-line option of the form:

--foo type=bar,active,nb_threads=8

This crate provides a from_key_values function that deserializes these key-values into a configuration structure. Since it uses serde, the same configuration structure can also be created from any other supported source (such as a TOML or YAML configuration file) that uses the same keys.

Integration with the argh command-line parser is also provided via the argh_derive feature.

See the inline documentation for examples and more details.