1use format_ende::FormatDecoder;
31use format_ende::FormatEncoder;
32use format_ende::FormatInfo;
33
34#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
36pub struct YamlFormat;
37
38impl YamlFormat {
39 pub const fn new() -> Self {
40 Self
41 }
42}
43
44impl Default for YamlFormat {
45 fn default() -> Self {
46 Self::new()
47 }
48}
49
50impl FormatInfo for YamlFormat {
51 fn file_extension(&self) -> &str {
52 "yaml"
53 }
54
55 fn is_utf8(&self) -> bool {
56 true
57 }
58}
59
60impl<V> FormatEncoder<V> for YamlFormat
61where
62 V: serde::Serialize + ?Sized,
63{
64 type EncodeError = serde_yaml::Error;
65
66 fn encode(
67 &mut self,
68 mut writer: impl std::io::Write,
69 value: &V,
70 ) -> Result<(), Self::EncodeError> {
71 serde_yaml::to_writer(&mut writer, value)
72 }
73}
74
75impl<V> FormatDecoder<V> for YamlFormat
76where
77 V: serde::de::DeserializeOwned,
78{
79 type DecodeError = serde_yaml::Error;
80
81 fn decode(&mut self, reader: impl std::io::Read) -> Result<V, Self::DecodeError> {
82 serde_yaml::from_reader(reader)
83 }
84}