1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
use crate::WriteBytes;

/// A trait for objects which can write [`str`] returning a specific output.
///
/// This trait is used by [`FmtWriter`] and [`ConcatWriter`] writers.
///
/// [`str`]: https://doc.rust-lang.org/std/str/index.html
/// [`FmtWriter`]: struct.FmtWriter.html
/// [`ConcatWriter`]: struct.ConcatWriter.html
pub trait WriteStr {
    /// The resulting type after writing.
    type Output;

    /// Performs byte writing.
    fn write_str(&mut self, buf: &str) -> Self::Output;
}

/// A trait for objects which should implement [`WriteStr`]
/// using their [`WriteBytes`] implementation.
pub trait WriteStrAsBytes: WriteBytes {}

impl<T> WriteStr for T
where
    T: WriteStrAsBytes,
{
    type Output = <T as WriteBytes>::Output;

    fn write_str(&mut self, buf: &str) -> Self::Output {
        self.write_bytes(buf.as_bytes())
    }
}