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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56

use ::std::io::Write;


mod std;
pub use self::std::*;

///The trait extends the capabilities of the standard Write.
pub trait ExtWrite<'a>: Write {
    type LockWrite: Write + 'a;

    ///Blocking the output stream.
    fn lock(&'a self) -> Self::LockWrite;

    ///Alternative method of blocking the output stream using the closure.
    #[inline(always)]
    fn lock_fn<F: FnMut(Self::LockWrite) -> R, R>(&'a self, mut f: F) -> R {
        f(self.lock())
    }
}


///The trait extends the capabilities of the standard Write.
impl<'a, 'l, L: ExtWrite<'a, LockWrite = W>, W: 'a + Write> ExtWrite<'a> for &'l L where Self: Write {
    type LockWrite = W;

    
    ///Blocking the output stream.
    #[inline(always)]
    fn lock(&'a self) -> Self::LockWrite {
        L::lock(self)
    }

    ///Alternative method of blocking the output stream using the closure.
    #[inline(always)]
    fn lock_fn<F: FnMut(Self::LockWrite) -> R, R>(&'a self, f: F) -> R {
        L::lock_fn(self, f)
    }
}

///The trait extends the capabilities of the standard Write.
impl<'a, 'l, L: ExtWrite<'a, LockWrite = W> + Write, W: 'a + Write> ExtWrite<'a> for &'l mut L where Self: Write {
    type LockWrite = W;

    ///Blocking the output stream.
    #[inline(always)]
    fn lock(&'a self) -> Self::LockWrite {
        L::lock(self)
    }

    ///Alternative method of blocking the output stream using the closure.
    #[inline(always)]
    fn lock_fn<F: FnMut(Self::LockWrite) -> R, R>(&'a self, f: F) -> R {
        L::lock_fn(self, f)
    }
}