martinohmann / hcl-rs

HCL parsing and encoding libraries for rust with serde support
Apache License 2.0
119 stars 14 forks source link

create `hcl::value::from_value` function just like `hcl::value::to_value` #345

Closed zkonge closed 2 months ago

zkonge commented 2 months ago

hi, I want to deserialize hcl::Value into my type T, but after reading through the code, I only found the hcl::value::to_value.

Is there any special reason execluding the from_value?

pub fn from_value<'de, T>(value: Value) -> Result<T>
where
    T: Deserialize<'de>,
{
    T::deserialize(ValueDeserializer::new(value))
}
martinohmann commented 2 months ago

Hi @zkonge,

there's no specific reason why from_value wasn't added yet. I didn't need it so far and nobody complained either :wink:.

Would you like to provide a PR to add it?

martinohmann commented 2 months ago

I'd probably go with the DeserializeOwned trait bound, similar to what serde_json does since we'll not borrow data from the deserializer here.