pub struct RemoveSoftLinesBuffer<'a, Context> { /* private fields */ }
Expand description

A Buffer that removes any soft line breaks.

§Examples

use biome_formatter::prelude::*;
use biome_formatter::{format, write};

use biome_formatter::{RemoveSoftLinesBuffer, SimpleFormatContext, VecBuffer};
use biome_formatter::prelude::format_with;
let formatted = format!(
    SimpleFormatContext::default(),
    [format_with(|f| {
        let mut buffer = RemoveSoftLinesBuffer::new(f);

        write!(
            buffer,
            [
                text("The next soft line or space gets replaced by a space"),
                soft_line_break_or_space(),
                text("and the line here"),
                soft_line_break(),
                text("is removed entirely.")
            ]
        )
    })]
)?;

assert_eq!(
    formatted.document().as_ref(),
    &[
        FormatElement::StaticText { text: "The next soft line or space gets replaced by a space" },
        FormatElement::Space,
        FormatElement::StaticText { text: "and the line here" },
        FormatElement::StaticText { text: "is removed entirely." }
    ]
);

Implementations§

source§

impl<'a, Context> RemoveSoftLinesBuffer<'a, Context>

source

pub fn new(inner: &'a mut dyn Buffer<Context = Context>) -> Self

Creates a new buffer that removes the soft line breaks before writing them into buffer.

Trait Implementations§

source§

impl<Context> Buffer for RemoveSoftLinesBuffer<'_, Context>

§

type Context = Context

The context used during formatting
source§

fn write_element(&mut self, element: FormatElement) -> FormatResult<()>

Writes a crate::FormatElement into this buffer, returning whether the write succeeded. Read more
source§

fn state(&self) -> &FormatState<Self::Context>

Returns the formatting state relevant for this formatting session.
source§

fn state_mut(&mut self) -> &mut FormatState<Self::Context>

Returns the mutable formatting state relevant for this formatting session.
source§

fn snapshot(&self) -> BufferSnapshot

Takes a snapshot of the Buffers state, excluding the formatter state.
source§

fn restore_snapshot(&mut self, snapshot: BufferSnapshot)

Restores the snapshot buffer Read more
source§

fn write_fmt( &mut self, arguments: Arguments<'_, Self::Context> ) -> FormatResult<()>

Glue for usage of the write! macro with implementors of this trait. Read more

Auto Trait Implementations§

§

impl<'a, Context> Freeze for RemoveSoftLinesBuffer<'a, Context>

§

impl<'a, Context> !RefUnwindSafe for RemoveSoftLinesBuffer<'a, Context>

§

impl<'a, Context> !Send for RemoveSoftLinesBuffer<'a, Context>

§

impl<'a, Context> !Sync for RemoveSoftLinesBuffer<'a, Context>

§

impl<'a, Context> Unpin for RemoveSoftLinesBuffer<'a, Context>

§

impl<'a, Context> !UnwindSafe for RemoveSoftLinesBuffer<'a, Context>

Blanket Implementations§

source§

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

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

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

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

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

source§

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

Mutably borrows from an owned value. Read more
source§

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

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 Read more
source§

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

Writes a sequence of elements into this buffer.
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T> Instrument for T

source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
source§

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

source§

fn into(self) -> U

Calls U::from(self).

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

source§

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

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

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

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

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

Performs the conversion.
source§

impl<T> WithSubscriber for T

source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more