1extern crate cluExtIO;
2
3use std::io::Error;
4use cluExtIO::UnionWriteConst;
5use cluExtIO::ExtWrite;
6use cluExtIO::MutexWrite;
7use cluExtIO::FlushLockWrite;
8use std::io::Write;
9use std::fs::File;
10
11pub fn main() -> Result<(), Error> {
12 let out = {
13 let std_out = std::io::stdout();
14
15 let file = FlushLockWrite::new(MutexWrite::new(File::create("/tmp/file.out")?));
16 let file2 = FlushLockWrite::new(MutexWrite::new(File::create("/tmp/file2.out")?));
20 std_out.union(file).union(file2)
24 }; my_function(&out, 0, "No eND:)")?;
27
28 out.lock_fn(|mut l| {
29 l.write(b"End.\n")
30 })?;
31
32 Ok( () )
37}
38
39fn my_function<'a, W: ExtWrite<'a>>(raw_write: &'a W, n: usize, str: &'static str) -> Result<(), std::io::Error> {
40 let mut lock = raw_write.lock();
41
42 lock.write_fmt(format_args!("#@{} {}\n", n, "Test"))?;
43 lock.write_fmt(format_args!("#@{} {}\n", n+1, "MyString"))?;
44
45 lock.write_fmt(format_args!("#@{} ~{}\n", n+2, str))
46}