spinoso_string/enc/
io.rs

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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
use core::fmt;
use std::io::{self, IoSlice, Write};

use super::EncodedString;

impl Write for EncodedString {
    #[inline]
    fn write(&mut self, buf: &[u8]) -> io::Result<usize> {
        match self {
            EncodedString::Ascii(inner) => inner.write(buf),
            EncodedString::Binary(inner) => inner.write(buf),
            EncodedString::Utf8(inner) => inner.write(buf),
        }
    }

    #[inline]
    fn write_all(&mut self, buf: &[u8]) -> io::Result<()> {
        match self {
            EncodedString::Ascii(inner) => inner.write_all(buf),
            EncodedString::Binary(inner) => inner.write_all(buf),
            EncodedString::Utf8(inner) => inner.write_all(buf),
        }
    }

    #[inline]
    fn write_fmt(&mut self, fmt: fmt::Arguments<'_>) -> io::Result<()> {
        match self {
            EncodedString::Ascii(inner) => inner.write_fmt(fmt),
            EncodedString::Binary(inner) => inner.write_fmt(fmt),
            EncodedString::Utf8(inner) => inner.write_fmt(fmt),
        }
    }

    #[inline]
    fn write_vectored(&mut self, bufs: &[IoSlice<'_>]) -> io::Result<usize> {
        match self {
            EncodedString::Ascii(inner) => inner.write_vectored(bufs),
            EncodedString::Binary(inner) => inner.write_vectored(bufs),
            EncodedString::Utf8(inner) => inner.write_vectored(bufs),
        }
    }

    #[inline]
    fn flush(&mut self) -> io::Result<()> {
        match self {
            EncodedString::Ascii(inner) => inner.flush(),
            EncodedString::Binary(inner) => inner.flush(),
            EncodedString::Utf8(inner) => inner.flush(),
        }
    }
}