ebarnard / rust-plist

A rusty plist parser.
MIT License
71 stars 42 forks source link

`Dictionary` should implement `From<HashMap<K, V>> where K: impl Into<Value>, V: impl Into<Value>` and `Into<HashMap<Value, Value>>` #63

Closed ctrlcctrlv closed 2 years ago

ctrlcctrlv commented 3 years ago

Not so sure about the definitions of K and V, but given that Date implements From<SystemTime> (that being the std::time::SystemTime, and that Array is just a Vec<T>, I think that it's a mistake that Dictionary cannot be converted back and forth from the standard std::collections::HashMap.

ebarnard commented 3 years ago

Dictionary keys are always strings.

The "standard" form for collection conversions in Rust seems to be .into_iter().collect(). Presumably because it works for all map types.

It might be worth extending:

impl FromIterator<(String, Value)> for Dictionary

to:

impl<K: Into<String>, V: Into<Value>> FromIterator<(K, V)> for Dictionary

so that people can convert like this:

let dict: Dictionary = hash_map.into_iter().collect();
ctrlcctrlv commented 3 years ago

Yeah, that works for me. :-)