write_scope/
with_std.rs

1use core::fmt;
2
3use crate::{Closer, CloserDynComp, Open, WriteScope};
4
5pub struct WrapIO<W>(pub W);
6
7impl<W: std::io::Write> Open for WrapIO<W> {
8    type Error = std::io::Error;
9
10    fn write_fmt(&mut self, arg: fmt::Arguments) -> Result<(), Self::Error> {
11        std::io::Write::write_fmt(&mut self.0, arg)
12    }
13
14    type W = Self;
15
16    fn writer(&mut self) -> &mut Self::W {
17        self
18    }
19}
20
21
22impl<W: Open> CloserDynComp<W> for Box<dyn CloserDynComp<W>> {
23    fn remove_from_dyn_comp(&mut self, w: &mut W) -> Result<(), W::Error> {
24        (**self).remove_from_dyn_comp(w)
25    }
26}
27
28impl<C: Closer, W: Open> WriteScope<C, W> {
29    pub fn closer_box_dyn(self) -> WriteScope<Box<dyn CloserDynComp<W>>, W>
30    where
31        C: 'static,
32    {
33        let (closer, writer) = self.deconstruct();
34        WriteScope {
35            closer: Box::new(closer),
36            writer,
37        }
38    }
39}