Struct runnel::RunnelIoeBuilder
source · 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§
source§impl RunnelIoeBuilder
impl RunnelIoeBuilder
sourcepub fn fill_stringio_with_str(self, arg: &str) -> Self
pub fn fill_stringio_with_str(self, arg: &str) -> Self
fill with stringio, arg as input
sourcepub fn fill_stringio(self, arg: String) -> Self
pub fn fill_stringio(self, arg: String) -> Self
fill with stringio, arg as input
Trait Implementations§
source§impl Debug for RunnelIoeBuilder
impl Debug for RunnelIoeBuilder
Auto Trait Implementations§
impl Freeze for RunnelIoeBuilder
impl RefUnwindSafe for RunnelIoeBuilder
impl Send for RunnelIoeBuilder
impl Sync for RunnelIoeBuilder
impl Unpin for RunnelIoeBuilder
impl UnwindSafe for RunnelIoeBuilder
Blanket Implementations§
source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more