| 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 |
pub fn new() -> Self { |
| 12 |
Default::default() |
| 13 |
} |
| 14 |
|
| 15 |
#[inline] |
| 16 |
pub fn with_capacity(capacity: usize) -> Self { |
| 17 |
Self(Vec::with_capacity(capacity)) |
| 18 |
} |
| 19 |
|
| 20 |
#[inline] |
| 21 |
pub fn as_bytes(&self) -> &[u8] { |
| 22 |
&self.0 |
| 23 |
} |
| 24 |
} |
| 25 |
|
| 26 |
impl AsRef<[u8]> for Buffer { |
| 27 |
#[inline] |
| 28 |
fn as_ref(&self) -> &[u8] { |
| 29 |
self.as_bytes() |
| 30 |
} |
| 31 |
} |
| 32 |
|
| 33 |
impl std::io::Write for Buffer { |
| 34 |
#[inline] |
| 35 |
fn write(&mut self, buf: &[u8]) -> std::io::Result<usize> { |
| 36 |
self.0.extend(buf); |
| 37 |
Ok(buf.len()) |
| 38 |
} |
| 39 |
|
| 40 |
#[inline] |
| 41 |
fn flush(&mut self) -> std::io::Result<()> { |
| 42 |
Ok(()) |
| 43 |
} |
| 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 |
} |