[][src]Struct linurgy::LinurgyBuilder

pub struct LinurgyBuilder<'a, 'b, 'c> { /* fields omitted */ }

Use this to prepare and execute linurgy editing on a stream.

A linurgy consists of an Input, which will be read line by line, edited by user defined rules, and then streamed into an Output.

Methods

impl<'a, 'b, 'c> LinurgyBuilder<'a, 'b, 'c>[src]

pub fn new() -> Self[src]

Instantiate a new builder with default values.

This will read from stdin, add dashes after 2 empty lines, and write to stdout.

pub fn set_input(&mut self, input: Input<'a>) -> &mut Self[src]

Set the input source to read text from.

Examples

Using an in-memory Buffer

let text = String::from("Sample text\n\n\n");
let mut linurgy = LinurgyBuilder::new();

linurgy.set_input(Input::Buffer(&text));

Read from a File

let mut linurgy = LinurgyBuilder::new();

linurgy.set_input(Input::File("filename.txt"));

pub fn set_output(&mut self, output: Output<'b>) -> &mut Self[src]

Set the output stream to write to.

Examples

Using an in-memory Buffer

let mut buffer = String::new();
let mut linurgy = LinurgyBuilder::new();

linurgy.set_output(Output::Buffer(&mut buffer));

Write straight to a File

let mut linurgy = LinurgyBuilder::new();

linurgy.set_output(Output::File("filename.txt"));

pub fn set_newline_trigger(&mut self, count: u8) -> &mut Self[src]

Set the newline count to trigger editing.

Example

Add edit string after every 5 empty lines

let mut linurgy = LinurgyBuilder::new();
linurgy.set_newline_trigger(5);

pub fn set_new_text(&mut self, new_text: &'c str) -> &mut Self[src]

Set the text that will be used when the newline trigger is reached.

Example

Add a line of dots after every empty line

let mut linurgy = LinurgyBuilder::new();
let new_text = format!("{}\n", ". ".repeat(25));

linurgy.set_newline_trigger(1);
linurgy.set_new_text(&new_text);

pub fn set_edit_type(&mut self, edit_type: EditType) -> &mut Self[src]

Set how new text is added after the newline trigger is reached.

Example

Replace double empty lines with a line of dashes

let mut linurgy = LinurgyBuilder::new();
linurgy.set_edit_type(EditType::Replace);

pub fn run(&mut self) -> Result<(), Error>[src]

Execute the linurgy edits on the specified input stream.

This function will block until the input stream is exhausted. If the input stream is Input::StdIn, then stdin will be locked while this function runs. If stdin is locked elsewhere, this function will block until it becomes available again.

Examples

Execute default behaviour and add dashes to double newlines from stdin

LinurgyBuilder::new().run()?;

Errors

If this function encounters any form of I/O or other error, an error variant will be returned.

Trait Implementations

impl<'a, 'b, 'c> Debug for LinurgyBuilder<'a, 'b, 'c>[src]

impl<'_, '_, '_> Default for LinurgyBuilder<'_, '_, '_>[src]

Auto Trait Implementations

impl<'a, 'b, 'c> RefUnwindSafe for LinurgyBuilder<'a, 'b, 'c>

impl<'a, 'b, 'c> Send for LinurgyBuilder<'a, 'b, 'c>

impl<'a, 'b, 'c> Sync for LinurgyBuilder<'a, 'b, 'c>

impl<'a, 'b, 'c> Unpin for LinurgyBuilder<'a, 'b, 'c>

impl<'a, 'b, 'c> !UnwindSafe for LinurgyBuilder<'a, 'b, 'c>

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

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

The type returned in the event of a conversion error.