toml_write/
write.rs

1pub trait TomlWrite: core::fmt::Write {
2    fn open_table_header(&mut self) -> core::fmt::Result {
3        write!(self, "[")
4    }
5    fn close_table_header(&mut self) -> core::fmt::Result {
6        write!(self, "]")
7    }
8
9    fn open_array_of_tables_header(&mut self) -> core::fmt::Result {
10        write!(self, "[[")
11    }
12    fn close_array_of_tables_header(&mut self) -> core::fmt::Result {
13        write!(self, "]]")
14    }
15
16    fn open_inline_table(&mut self) -> core::fmt::Result {
17        write!(self, "{{")
18    }
19    fn close_inline_table(&mut self) -> core::fmt::Result {
20        write!(self, "}}")
21    }
22
23    fn open_array(&mut self) -> core::fmt::Result {
24        write!(self, "[")
25    }
26    fn close_array(&mut self) -> core::fmt::Result {
27        write!(self, "]")
28    }
29
30    fn key_sep(&mut self) -> core::fmt::Result {
31        write!(self, ".")
32    }
33
34    fn keyval_sep(&mut self) -> core::fmt::Result {
35        write!(self, "=")
36    }
37
38    fn key(&mut self, value: impl crate::WriteTomlKey) -> core::fmt::Result {
39        value.write_toml_key(self)
40    }
41
42    /// <div class="warning">
43    ///
44    /// For floats, this preserves the sign bit for [`f32::NAN`] / [`f64::NAN`] for the sake of
45    /// format-preserving editing.
46    /// However, in most cases the sign bit is indeterminate and outputting signed NANs can be a
47    /// cause of non-repeatable behavior.
48    ///
49    /// For general serialization, you should discard the sign bit.  For example:
50    /// ```
51    /// # let mut v = f64::NAN;
52    /// if v.is_nan() {
53    ///     v = v.copysign(1.0);
54    /// }
55    /// ```
56    ///
57    /// </div>
58    fn value(&mut self, value: impl crate::WriteTomlValue) -> core::fmt::Result {
59        value.write_toml_value(self)
60    }
61
62    fn val_sep(&mut self) -> core::fmt::Result {
63        write!(self, ",")
64    }
65
66    fn space(&mut self) -> core::fmt::Result {
67        write!(self, " ")
68    }
69
70    fn open_comment(&mut self) -> core::fmt::Result {
71        write!(self, "#")
72    }
73
74    fn newline(&mut self) -> core::fmt::Result {
75        writeln!(self)
76    }
77}
78
79impl<W> TomlWrite for W where W: core::fmt::Write {}