goods_yaml/lib.rs
1use {goods::SimpleFormat, serde::de::DeserializeOwned};
2
3/// Format that treats bytes as YAML document and deserializes asset representation with `serde`.
4#[derive(Copy, Clone, Debug, Default, PartialEq, Eq, Hash)]
5#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
6pub struct YamlFormat;
7
8impl<A, K> SimpleFormat<A, K> for YamlFormat
9where
10 A: DeserializeOwned,
11{
12 fn decode_simple(self, _key: K, bytes: Box<[u8]>) -> eyre::Result<A> {
13 serde_yaml::from_slice(&bytes).map_err(Into::into)
14 }
15}