pub trait BufferExtensions: Buffer + Sized {
    // Provided methods
    fn inspect<F>(&mut self, inspector: F) -> Inspect<'_, Self::Context, F>
       where F: FnMut(&FormatElement) { ... }
    fn start_recording(&mut self) -> Recording<'_, Self> { ... }
    fn write_elements<I>(&mut self, elements: I) -> FormatResult<()>
       where I: IntoIterator<Item = FormatElement> { ... }
}

Provided Methods§

source

fn inspect<F>(&mut self, inspector: F) -> Inspect<'_, Self::Context, F>
where F: FnMut(&FormatElement),

Returns a new buffer that calls the passed inspector for every element that gets written to the output

source

fn start_recording(&mut self) -> Recording<'_, Self>

Starts a recording that gives you access to all elements that have been written between the start and end of the recording

#Examples

use std::ops::Deref;
use biome_formatter::prelude::*;
use biome_formatter::{write, format, SimpleFormatContext};

let formatted = format!(SimpleFormatContext::default(), [format_with(|f| {
    let mut recording = f.start_recording();

    write!(recording, [text("A")])?;
    write!(recording, [text("B")])?;

    write!(recording, [format_with(|f| write!(f, [text("C"), text("D")]))])?;

    let recorded = recording.stop();
    assert_eq!(
        recorded.deref(),
        &[
            FormatElement::StaticText{ text: "A" },
            FormatElement::StaticText{ text: "B" },
            FormatElement::StaticText{ text: "C" },
            FormatElement::StaticText{ text: "D" }
        ]
    );

    Ok(())
})])?;

assert_eq!(formatted.print()?.as_code(), "ABCD");
source

fn write_elements<I>(&mut self, elements: I) -> FormatResult<()>
where I: IntoIterator<Item = FormatElement>,

Writes a sequence of elements into this buffer.

Object Safety§

This trait is not object safe.

Implementors§

source§

impl<T> BufferExtensions for T
where T: Buffer,