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
//! The simple writer
//!
//! Requires the `simple_writer` feature.

use std::io;
use std::fmt;
use encode;

/// An `encode::Write`r that simply delegates to an `io::Write`r and relies
/// on the default implementations of `encode::Write`r methods.
#[derive(Debug)]
pub struct SimpleWriter<W>(pub W);

impl<W: io::Write> io::Write for SimpleWriter<W> {
    fn write(&mut self, buf: &[u8]) -> io::Result<usize> {
        self.0.write(buf)
    }

    fn flush(&mut self) -> io::Result<()> {
        self.0.flush()
    }

    fn write_all(&mut self, buf: &[u8]) -> io::Result<()> {
        self.0.write_all(buf)
    }

    fn write_fmt(&mut self, fmt: fmt::Arguments) -> io::Result<()> {
        self.0.write_fmt(fmt)
    }
}

impl<W: io::Write> encode::Write for SimpleWriter<W> {}