Introduce Token element (#7048)

This commit is contained in:
Micha Reiser 2023-09-02 10:05:47 +02:00 committed by GitHub
parent 2f3a950f6f
commit c05e4628b1
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
78 changed files with 733 additions and 723 deletions

View file

@ -25,9 +25,9 @@ pub trait Buffer {
/// let mut state = FormatState::new(SimpleFormatContext::default());
/// let mut buffer = VecBuffer::new(&mut state);
///
/// buffer.write_element(FormatElement::StaticText { text: "test"});
/// buffer.write_element(FormatElement::Token { text: "test"});
///
/// assert_eq!(buffer.into_vec(), vec![FormatElement::StaticText { text: "test" }]);
/// assert_eq!(buffer.into_vec(), vec![FormatElement::Token { text: "test" }]);
/// ```
fn write_element(&mut self, element: FormatElement);
@ -50,9 +50,9 @@ pub trait Buffer {
/// let mut state = FormatState::new(SimpleFormatContext::default());
/// let mut buffer = VecBuffer::new(&mut state);
///
/// buffer.write_fmt(format_args!(text("Hello World"))).unwrap();
/// buffer.write_fmt(format_args!(token("Hello World"))).unwrap();
///
/// assert_eq!(buffer.into_vec(), vec![FormatElement::StaticText{ text: "Hello World" }]);
/// assert_eq!(buffer.into_vec(), vec![FormatElement::Token{ text: "Hello World" }]);
/// ```
fn write_fmt(mut self: &mut Self, arguments: Arguments<Self::Context>) -> FormatResult<()> {
write(&mut self, arguments)
@ -316,11 +316,11 @@ where
/// write!(
/// buffer,
/// [
/// text("The next soft line or space gets replaced by a space"),
/// token("The next soft line or space gets replaced by a space"),
/// soft_line_break_or_space(),
/// text("and the line here"),
/// token("and the line here"),
/// soft_line_break(),
/// text("is removed entirely.")
/// token("is removed entirely.")
/// ]
/// )
/// })]
@ -329,10 +329,10 @@ where
/// assert_eq!(
/// formatted.document().as_ref(),
/// &[
/// FormatElement::StaticText { text: "The next soft line or space gets replaced by a space" },
/// FormatElement::Token { 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." }
/// FormatElement::Token { text: "and the line here" },
/// FormatElement::Token { text: "is removed entirely." }
/// ]
/// );
///
@ -488,19 +488,19 @@ pub trait BufferExtensions: Buffer + Sized {
/// let formatted = format!(SimpleFormatContext::default(), [format_with(|f| {
/// let mut recording = f.start_recording();
///
/// write!(recording, [text("A")])?;
/// write!(recording, [text("B")])?;
/// write!(recording, [token("A")])?;
/// write!(recording, [token("B")])?;
///
/// write!(recording, [format_with(|f| write!(f, [text("C"), text("D")]))])?;
/// write!(recording, [format_with(|f| write!(f, [token("C"), token("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" }
/// FormatElement::Token{ text: "A" },
/// FormatElement::Token{ text: "B" },
/// FormatElement::Token{ text: "C" },
/// FormatElement::Token{ text: "D" }
/// ]
/// );
///