Struct runnel::RunnelIoeBuilder [−][src]
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
impl RunnelIoeBuilder
[src]
pub fn new() -> Self
[src]
create builder
pub fn pin<T: 'static + StreamIn>(self, a: T) -> Self
[src]
set pluggable stream in
pub fn pout<T: 'static + StreamOut>(self, a: T) -> Self
[src]
set pluggable stream out
pub fn perr<T: 'static + StreamErr>(self, a: T) -> Self
[src]
set pluggable stream err
pub fn build(self) -> RunnelIoe
[src]
build to RunnelIoe
pub fn fill_stringio_with_str(self, arg: &str) -> Self
[src]
fill with stringio, arg as input
pub fn fill_stringio(self, arg: String) -> Self
[src]
fill with stringio, arg as input
Trait Implementations
impl Debug for RunnelIoeBuilder
[src]
impl Default for RunnelIoeBuilder
[src]
Auto Trait Implementations
impl RefUnwindSafe for RunnelIoeBuilder
[src]
impl Send for RunnelIoeBuilder
[src]
impl Sync for RunnelIoeBuilder
[src]
impl Unpin for RunnelIoeBuilder
[src]
impl UnwindSafe for RunnelIoeBuilder
[src]
Blanket Implementations
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
pub fn borrow_mut(&mut self) -> &mut T
[src]
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.
pub 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>,