pub struct RunnelIoeBuilder { /* private fields */ }
Expand description

The builder for RunnelIoe

Examples

Example: fill stdio

build RunnelIoe has std::io::stdin(), std::io::stdout(), std::io::stderr(),

use runnel::RunnelIoeBuilder;
let sioe = RunnelIoeBuilder::new().build();

Example: fill stringio

build RunnelIoe has medium::stringio::StringIn, medium::stringio::StringOut, medium::stringio::StringErr,

use runnel::RunnelIoeBuilder;
use runnel::medium::stringio::{StringIn, StringOut, StringErr};
let sioe = RunnelIoeBuilder::new()
    .pin(StringIn::with_str("abcdefg"))
    .pout(StringOut::default())
    .perr(StringErr::default())
    .build();

Example: fill stringio by fill_stringio_with_str()

build RunnelIoe has medium::stringio::StringIn, medium::stringio::StringOut, medium::stringio::StringErr,

use runnel::RunnelIoeBuilder;
let sioe = RunnelIoeBuilder::new()
    .fill_stringio_with_str("abcdefg")
    .build();

Example: stdio and pipe

This case is multi-threads. read stdin on working thread, write stdout on main thread. The data is through in-memory pipe.

use runnel::RunnelIoeBuilder;
use runnel::medium::pipeio::pipe;
use std::io::{BufRead, Write};

fn run() -> std::io::Result<()> {
    let (a_out, a_in) = pipe(1);

    // a working thread
    #[rustfmt::skip]
    let sioe = RunnelIoeBuilder::new().pout(a_out).build();
    let handler = std::thread::spawn(move || {
        for line in sioe.pin().lock().lines().map(|l| l.unwrap()) {
            let mut out = sioe.pout().lock();
            out.write_fmt(format_args!("{}\n", line)).unwrap();
            out.flush().unwrap();
        }
    });

    // a main thread
    #[rustfmt::skip]
    let sioe = RunnelIoeBuilder::new().pin(a_in).build();
    for line in sioe.pin().lock().lines() {
        let line_s = line?;
        let mut out = sioe.pout().lock();
        out.write_fmt(format_args!("{}\n", line_s))?;
        out.flush()?;
    }
    Ok(())
}

Implementations

create builder

set pluggable stream in

set pluggable stream out

set pluggable stream err

build to RunnelIoe

fill with stringio, arg as input

fill with stringio, arg as input

Trait Implementations

Formats the value using the given formatter. Read more

Returns the “default value” for a type. Read more

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Returns the argument unchanged.

Calls U::from(self).

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

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.