Struct Buffer

pub struct Buffer(/* private field */);

Write colored text to memory.

Buffer is a platform independent abstraction for printing colored text to an in memory buffer. When the buffer is printed using a BufferWriter, the color information will be applied to the output device (a tty on Unix and a console on Windows).

A Buffer is typically created by calling the BufferWriter.buffer method, which will take color preferences and the environment into account. However, buffers can also be manually created using no_color, ansi or console (on Windows).

Implementations

impl Buffer

fn no_color() -> Buffer

Create a buffer that drops all color information.

fn ansi() -> Buffer

Create a buffer that uses ANSI escape sequences.

fn is_empty(&self) -> bool

Returns true if and only if this buffer is empty.

fn len(&self) -> usize

Returns the length of this buffer in bytes.

fn clear(&mut self)

Clears this buffer.

fn into_inner(self) -> Vec<u8>

Consume this buffer and return the underlying raw data.

On Windows, this unrecoverably drops all color information associated with the buffer.

fn as_slice(&self) -> &[u8]

Return the underlying data of the buffer.

fn as_mut_slice(&mut self) -> &mut [u8]

Return the underlying data of the buffer as a mutable slice.

Trait Implementations

impl Clone for Buffer

fn clone(&self) -> Self

impl Debug for Buffer

fn fmt(&self, f: &mut Formatter<'_>) -> Result

impl Write for Buffer

fn write(&mut self, buf: &[u8]) -> Result<usize>
fn flush(&mut self) -> Result<()>

impl WriteColor for Buffer

fn supports_color(&self) -> bool
fn set_color(&mut self, spec: &ColorSpec) -> Result<()>
fn reset(&mut self) -> Result<()>
fn is_synchronous(&self) -> bool

Auto Trait Implementations

impl Freeze for Buffer

impl RefUnwindSafe for Buffer

impl Send for Buffer

impl Sync for Buffer

impl Unpin for Buffer

impl UnsafeUnpin for Buffer

impl UnwindSafe for Buffer

Blanket Implementations

impl<T> Any for Buffer where T: 'static + ?Sized,

fn type_id(&self) -> TypeId

impl<T> Borrow<T> for Buffer where T: ?Sized,

fn borrow(&self) -> &T

impl<T> BorrowMut<T> for Buffer where T: ?Sized,

fn borrow_mut(&mut self) -> &mut T

impl<T> CloneToUninit for Buffer where T: Clone,

unsafe fn clone_to_uninit(&self, dest: *mut u8)

impl<T> From<T> for Buffer

fn from(t: T) -> T

Returns the argument unchanged.

impl<T> ToOwned for Buffer where T: Clone,

type Owned = T;
fn to_owned(&self) -> T
fn clone_into(&self, target: &mut T)

impl<T, U> Into<U> for Buffer where U: From<T>,

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of [From]<T> for U chooses to do.

impl<T, U> TryFrom<U> for Buffer where U: Into<T>,

type Error = never;
fn try_from(value: U) -> Result<T, never>

impl<T, U> TryInto<U> for Buffer where U: TryFrom<T>,

type Error = <U as TryFrom<T>>::Error;
fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>