cluExtIO/write/ext_write/
mod.rs

1
2use ::std::io::Write;
3
4
5mod std;
6pub use self::std::*;
7
8///The trait extends the capabilities of the standard Write.
9pub trait ExtWrite<'a>: Write {
10    type LockWrite: Write + 'a;
11
12    ///Blocking the output stream.
13    fn lock(&'a self) -> Self::LockWrite;
14
15    ///Alternative method of blocking the output stream using the closure.
16    #[inline(always)]
17    fn lock_fn<F: FnMut(Self::LockWrite) -> R, R>(&'a self, mut f: F) -> R {
18        f(self.lock())
19    }
20}
21
22
23///The trait extends the capabilities of the standard Write.
24impl<'a, 'l, L: ExtWrite<'a, LockWrite = W>, W: 'a + Write> ExtWrite<'a> for &'l L where Self: Write {
25    type LockWrite = W;
26
27    
28    ///Blocking the output stream.
29    #[inline(always)]
30    fn lock(&'a self) -> Self::LockWrite {
31        L::lock(self)
32    }
33
34    ///Alternative method of blocking the output stream using the closure.
35    #[inline(always)]
36    fn lock_fn<F: FnMut(Self::LockWrite) -> R, R>(&'a self, f: F) -> R {
37        L::lock_fn(self, f)
38    }
39}
40
41///The trait extends the capabilities of the standard Write.
42impl<'a, 'l, L: ExtWrite<'a, LockWrite = W> + Write, W: 'a + Write> ExtWrite<'a> for &'l mut L where Self: Write {
43    type LockWrite = W;
44
45    ///Blocking the output stream.
46    #[inline(always)]
47    fn lock(&'a self) -> Self::LockWrite {
48        L::lock(self)
49    }
50
51    ///Alternative method of blocking the output stream using the closure.
52    #[inline(always)]
53    fn lock_fn<F: FnMut(Self::LockWrite) -> R, R>(&'a self, f: F) -> R {
54        L::lock_fn(self, f)
55    }
56}