kv-derive
Derive struct
conversions from and to key-value vectors using ToString
and FromStr
.
#[derive(ToVec)]
```rust use kv_derive::ToVec;
struct Foo { bar: i32, qux: String, }
let foo = Foo { bar: 42, qux: "qux".into() }; asserteq!(foo.tovec(), vec![ ("bar", "42".into()), ("qux", "qux".into()), ]); ```
#[derive(FromIter)]
```rust use kv_derive::FromIter;
struct Foo { bar: i32, qux: String, }
let actual = Foo::fromiter(vec![("bar", "42"), ("qux", "quuux")]).unwrap(); let expected = Foo { bar: 42, qux: "quuux".into() }; asserteq!(actual, expected); ```
FromIter
requires that the deriving struct implements Default
because some fields may be missing in the iterator.