extern crate cluExtIO;
use std::io::Error;
use cluExtIO::UnionWriteConst;
use cluExtIO::ExtWrite;
use cluExtIO::MutexWrite;
use cluExtIO::FlushLockWrite;
use std::io::Write;
use std::fs::File;
pub fn main() -> Result<(), Error> {
let out = {
let std_out = std::io::stdout();
let file = FlushLockWrite::new(MutexWrite::new(File::create("/tmp/file.out")?));
let file2 = FlushLockWrite::new(MutexWrite::new(File::create("/tmp/file2.out")?));
std_out.union(file).union(file2)
};
my_function(&out, 0, "No eND:)")?;
out.lock_fn(|mut l| {
l.write(b"End.\n")
})?;
Ok( () )
}
fn my_function<'a, W: ExtWrite<'a>>(raw_write: &'a W, n: usize, str: &'static str) -> Result<(), std::io::Error> {
let mut lock = raw_write.lock();
lock.write_fmt(format_args!("#@{} {}\n", n, "Test"))?;
lock.write_fmt(format_args!("#@{} {}\n", n+1, "MyString"))?;
lock.write_fmt(format_args!("#@{} ~{}\n", n+2, str))
}