crosvm/serde_keyvalue
Alexandre Courbot e91b0fd604 serde_keyvalue: support for tuple and struct enums
Up to now only unit enums were supported. Add support for tuple and
struct enums, which can deserialize the following enum

    enum VideoMode {
        Fullscreen,
        Window(u32, u32),
        Remote { host: String },
    }

from the following inputs:

    mode=fullscreen
    mode=window[640,480]
    mode=remote[host=workstation]

This allows us to stop using flattened or dedicated enums for parsing and also
results in a less ambiguous syntax for these cases.

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

Change-Id: I142fc91fab19f4a977adec3ee36094e5f95363db
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/3915040
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Commit-Queue: Alexandre Courbot <acourbot@chromium.org>
Reviewed-by: Dennis Kempin <denniskempin@google.com>
2022-10-05 07:03:48 +00:00
..
serde_keyvalue_derive
src serde_keyvalue: support for tuple and struct enums 2022-10-05 07:03:48 +00:00
Cargo.toml
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.