custom_print/
write_str.rs

1use crate::WriteBytes;
2
3/// A trait for objects which can write [`str`] returning a specific output.
4///
5/// This trait is used by [`FmtWriter`] and [`ConcatWriter`] writers.
6///
7/// [`str`]: https://doc.rust-lang.org/std/str/index.html
8/// [`FmtWriter`]: struct.FmtWriter.html
9/// [`ConcatWriter`]: struct.ConcatWriter.html
10pub trait WriteStr {
11    /// The resulting type after writing.
12    type Output;
13
14    /// Performs byte writing.
15    fn write_str(&mut self, buf: &str) -> Self::Output;
16}
17
18/// A trait for objects which should implement [`WriteStr`]
19/// using their [`WriteBytes`] implementation.
20pub trait WriteStrAsBytes: WriteBytes {}
21
22impl<T> WriteStr for T
23where
24    T: WriteStrAsBytes,
25{
26    type Output = <T as WriteBytes>::Output;
27
28    fn write_str(&mut self, buf: &str) -> Self::Output {
29        self.write_bytes(buf.as_bytes())
30    }
31}