1use std::cell::RefCell;
2use std::io::{self, Write};
3use std::rc::Rc;
4
5pub struct RcWriter<W: Write> {
6 inner: Rc<RefCell<W>>,
7}
8
9impl<W: Write> RcWriter<W> {
10 #[inline]
11 pub fn new(writer: Rc<RefCell<W>>) -> RcWriter<W> {
12 RcWriter {
13 inner: writer,
14 }
15 }
16}
17
18impl<W: Write> Write for RcWriter<W> {
19 #[inline]
20 fn write(&mut self, buf: &[u8]) -> Result<usize, io::Error> {
21 self.inner.borrow_mut().write(buf)
22 }
23
24 #[inline]
25 fn flush(&mut self) -> Result<(), io::Error> {
26 self.inner.borrow_mut().flush()
27 }
28}