spinoso_string/enc/
io.rs

1use core::fmt;
2use std::io::{self, IoSlice, Write};
3
4use super::EncodedString;
5
6impl Write for EncodedString {
7    #[inline]
8    fn write(&mut self, buf: &[u8]) -> io::Result<usize> {
9        match self {
10            EncodedString::Ascii(inner) => inner.write(buf),
11            EncodedString::Binary(inner) => inner.write(buf),
12            EncodedString::Utf8(inner) => inner.write(buf),
13        }
14    }
15
16    #[inline]
17    fn write_all(&mut self, buf: &[u8]) -> io::Result<()> {
18        match self {
19            EncodedString::Ascii(inner) => inner.write_all(buf),
20            EncodedString::Binary(inner) => inner.write_all(buf),
21            EncodedString::Utf8(inner) => inner.write_all(buf),
22        }
23    }
24
25    #[inline]
26    fn write_fmt(&mut self, fmt: fmt::Arguments<'_>) -> io::Result<()> {
27        match self {
28            EncodedString::Ascii(inner) => inner.write_fmt(fmt),
29            EncodedString::Binary(inner) => inner.write_fmt(fmt),
30            EncodedString::Utf8(inner) => inner.write_fmt(fmt),
31        }
32    }
33
34    #[inline]
35    fn write_vectored(&mut self, bufs: &[IoSlice<'_>]) -> io::Result<usize> {
36        match self {
37            EncodedString::Ascii(inner) => inner.write_vectored(bufs),
38            EncodedString::Binary(inner) => inner.write_vectored(bufs),
39            EncodedString::Utf8(inner) => inner.write_vectored(bufs),
40        }
41    }
42
43    #[inline]
44    fn flush(&mut self) -> io::Result<()> {
45        match self {
46            EncodedString::Ascii(inner) => inner.flush(),
47            EncodedString::Binary(inner) => inner.flush(),
48            EncodedString::Utf8(inner) => inner.flush(),
49        }
50    }
51}