kutil_std/
dyn_writer.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
use std::io::*;

//
// DynWriter
//

/// Provides a concrete [Write] implementation for `dyn` [Write].
pub struct DynWriter<'a> {
    writer: &'a mut dyn Write,
}

impl<'a> DynWriter<'a> {
    /// Constructor.
    pub fn new(writer: &'a mut dyn Write) -> Self {
        Self { writer }
    }
}

impl<'a> Write for DynWriter<'a> {
    fn write(&mut self, buf: &[u8]) -> Result<usize> {
        self.writer.write(buf)
    }

    fn flush(&mut self) -> Result<()> {
        self.writer.flush()
    }
}