Coverage Report

Created: 2025-07-23 06:05

/rust/registry/src/index.crates.io-6f17d22bba15001f/anstream-0.6.18/src/buffer.rs
Line
Count
Source (jump to first uncovered line)
1
#![allow(deprecated)]
2
3
/// In-memory [`RawStream`][crate::stream::RawStream]
4
#[derive(Clone, Default, Debug, PartialEq, Eq)]
5
#[deprecated(since = "0.6.2", note = "Use Vec")]
6
#[doc(hidden)]
7
pub struct Buffer(Vec<u8>);
8
9
impl Buffer {
10
    #[inline]
11
0
    pub fn new() -> Self {
12
0
        Default::default()
13
0
    }
14
15
    #[inline]
16
0
    pub fn with_capacity(capacity: usize) -> Self {
17
0
        Self(Vec::with_capacity(capacity))
18
0
    }
19
20
    #[inline]
21
0
    pub fn as_bytes(&self) -> &[u8] {
22
0
        &self.0
23
0
    }
24
}
25
26
impl AsRef<[u8]> for Buffer {
27
    #[inline]
28
0
    fn as_ref(&self) -> &[u8] {
29
0
        self.as_bytes()
30
0
    }
31
}
32
33
impl std::io::Write for Buffer {
34
    #[inline]
35
0
    fn write(&mut self, buf: &[u8]) -> std::io::Result<usize> {
36
0
        self.0.extend(buf);
37
0
        Ok(buf.len())
38
0
    }
39
40
    #[inline]
41
0
    fn flush(&mut self) -> std::io::Result<()> {
42
0
        Ok(())
43
0
    }
44
}
45
46
#[cfg(all(windows, feature = "wincon"))]
47
impl anstyle_wincon::WinconStream for Buffer {
48
    fn write_colored(
49
        &mut self,
50
        fg: Option<anstyle::AnsiColor>,
51
        bg: Option<anstyle::AnsiColor>,
52
        data: &[u8],
53
    ) -> std::io::Result<usize> {
54
        self.0.write_colored(fg, bg, data)
55
    }
56
}