maximum/
maximum.rs

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          //Contains the implementation of ExtWrite. Safe for inter-thread space.
17          //+ Additional self-cleaning after destroying Lock
18
19          let file2 = FlushLockWrite::new(MutexWrite::new(File::create("/tmp/file2.out")?));
20          //Contains the implementation of ExtWrite. Safe for inter-thread space.
21          //+ Additional self-cleaning after destroying Lock
22          
23          std_out.union(file).union(file2)
24     }; //Combined `ExtWrite` with lock function. OUT_PIPE + FILE_PIPE(2) = UNION_SAFE_PIPE
25
26     my_function(&out, 0, "No eND:)")?;
27     
28     out.lock_fn(|mut l| {
29          l.write(b"End.\n")
30     })?;
31
32     // STDOUT+
33     // /tmp/file.out+
34     // /tmp/file.out+
35
36     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}