[−][src]Struct sise::SpacedStringWriter
Writer that writes everything into a multi-line string.
Example
use sise::Writer as _; let style = sise::SpacedStringWriterStyle { line_break: "\n", indentation: " ", }; let mut result = String::new(); let mut writer = sise::SpacedStringWriter::new(style, &mut result); writer.begin_list(&sise::SpacedStringWriterNodeOptions::default()).unwrap(); writer.write_atom("example", &sise::SpacedStringWriterNodeOptions::default()).unwrap(); writer.begin_list(&sise::SpacedStringWriterNodeOptions::default()).unwrap(); // Write the three atoms in a single line. writer.write_atom("1", &sise::SpacedStringWriterNodeOptions::default()).unwrap(); writer.write_atom("2", &sise::SpacedStringWriterNodeOptions::default()).unwrap(); writer.write_atom("3", &sise::SpacedStringWriterNodeOptions::default()).unwrap(); writer.end_list(&sise::VoidWriterOptions).unwrap(); writer.begin_list(&sise::SpacedStringWriterNodeOptions::default()).unwrap(); // Write the three atoms in a single line. writer.write_atom("a", &sise::SpacedStringWriterNodeOptions::default()).unwrap(); writer.write_atom("b", &sise::SpacedStringWriterNodeOptions::default()).unwrap(); writer.write_atom("c", &sise::SpacedStringWriterNodeOptions::default()).unwrap(); writer.end_list(&sise::VoidWriterOptions).unwrap(); writer.end_list(&sise::VoidWriterOptions).unwrap(); writer.finish(&sise::VoidWriterOptions).unwrap(); let expected_result = "(\n example\n (\n 1\n 2\n 3\n )\n (\n a\n b\n c\n )\n)"; assert_eq!(result, expected_result);
Using SpacedStringWriterNodeOptions
allows to write specified nodes
in a single line:
use sise::Writer as _; let style = sise::SpacedStringWriterStyle { line_break: "\n", indentation: " ", }; let mut result = String::new(); let mut writer = sise::SpacedStringWriter::new(style, &mut result); writer.begin_list(&sise::SpacedStringWriterNodeOptions::default()).unwrap(); writer.write_atom("example", &sise::SpacedStringWriterNodeOptions::no_break_line()).unwrap(); writer.begin_list(&sise::SpacedStringWriterNodeOptions::break_line()).unwrap(); // Write the three atoms in a single line. writer.write_atom("1", &sise::SpacedStringWriterNodeOptions::no_break_line()).unwrap(); writer.write_atom("2", &sise::SpacedStringWriterNodeOptions::no_break_line()).unwrap(); writer.write_atom("3", &sise::SpacedStringWriterNodeOptions::no_break_line()).unwrap(); writer.end_list(&sise::VoidWriterOptions).unwrap(); writer.begin_list(&sise::SpacedStringWriterNodeOptions::break_line()).unwrap(); // Write the three atoms in a single line. writer.write_atom("a", &sise::SpacedStringWriterNodeOptions::no_break_line()).unwrap(); writer.write_atom("b", &sise::SpacedStringWriterNodeOptions::no_break_line()).unwrap(); writer.write_atom("c", &sise::SpacedStringWriterNodeOptions::no_break_line()).unwrap(); writer.end_list(&sise::VoidWriterOptions).unwrap(); writer.end_list(&sise::VoidWriterOptions).unwrap(); writer.finish(&sise::VoidWriterOptions).unwrap(); let expected_result = "(example\n (1 2 3)\n (a b c)\n)"; assert_eq!(result, expected_result);
Methods
impl<'a, 'b> SpacedStringWriter<'a, 'b>
[src]
pub fn new(style: SpacedStringWriterStyle<'a>, dst: &'b mut String) -> Self
[src]
Trait Implementations
impl<'a, 'b> Writer for SpacedStringWriter<'a, 'b>
[src]
type Result = ()
Type of data returned by the writer.
type Error = Infallible
The error type that may be produced while writing.
type AtomOptions = SpacedStringWriterNodeOptions
Type of options that can be passed to write_atom
.
type BeginListOptions = SpacedStringWriterNodeOptions
Type of options that can be passed to begin_list
.
type EndListOptions = VoidWriterOptions
Type of options that can be passed to end_list
.
type FinishOptions = VoidWriterOptions
Type of options that can be passed to finish
.
fn write_atom(
&mut self,
atom: &str,
opts: &SpacedStringWriterNodeOptions
) -> Result<(), Infallible>
[src]
&mut self,
atom: &str,
opts: &SpacedStringWriterNodeOptions
) -> Result<(), Infallible>
fn begin_list(
&mut self,
opts: &SpacedStringWriterNodeOptions
) -> Result<(), Infallible>
[src]
&mut self,
opts: &SpacedStringWriterNodeOptions
) -> Result<(), Infallible>
fn end_list(&mut self, _opts: &VoidWriterOptions) -> Result<(), Infallible>
[src]
fn finish(self, _opts: &VoidWriterOptions) -> Result<(), Infallible>
[src]
Auto Trait Implementations
impl<'a, 'b> Send for SpacedStringWriter<'a, 'b>
impl<'a, 'b> Unpin for SpacedStringWriter<'a, 'b>
impl<'a, 'b> Sync for SpacedStringWriter<'a, 'b>
impl<'a, 'b> !UnwindSafe for SpacedStringWriter<'a, 'b>
impl<'a, 'b> RefUnwindSafe for SpacedStringWriter<'a, 'b>
Blanket Implementations
impl<T> From<T> for T
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,
type Error = <U as TryFrom<T>>::Error
The type returned in the event of a conversion error.
fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>
[src]
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,