Trait UnionWriteConst

Source
pub trait UnionWriteConst: Write {
    // Provided method
    fn union<B: Write>(self, b: B) -> UnionWrite<Self, B> 
       where Self: Sized { ... }
}
Expand description

Implementing the Union Write constructor for Write.

Provided Methods§

Source

fn union<B: Write>(self, b: B) -> UnionWrite<Self, B>
where Self: Sized,

Examples found in repository?
examples/union.rs (line 18)
10pub fn main() -> Result<(), Error> {
11
12     let file1 = File::create("/tmp/1.out")?;
13     //file1 - `Write trait`
14
15     let file2 = File::create("/tmp/2.out")?;
16     //file2 - `Write trait`
17
18     let write = file1.union(file2);
19     //UnionWrite - `FILE1+FILE2`
20
21
22     my_function(write)
23}
More examples
Hide additional examples
examples/maximum.rs (line 23)
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}
examples/thread.rs (line 28)
16pub fn main() {
17     let arc_out = Arc::new({       
18          let out = stdout();
19
20          let file = FlushLockWrite::new(MutexWrite::new(File::create("/tmp/file.out").unwrap()));
21          //Contains the implementation of ExtWrite. Safe for inter-thread space.
22          //+ Additional self-cleaning after destroying Lock
23
24          let file2 = FlushLockWrite::new(MutexWrite::new(File::create("/tmp/file2.out").unwrap()));
25          //Contains the implementation of ExtWrite. Safe for inter-thread space.
26          //+ Additional self-cleaning after destroying Lock
27          
28          out.union(file).union(file2)
29     }); //Combined `ExtWrite` with lock function. OUT_PIPE + FILE_PIPE(2) = UNION_SAFE_PIPE
30
31
32     let barrier = Arc::new(Barrier::new(5 + 1));
33
34     for num_thread in 0..5 {
35          let barrier = barrier.clone();
36          let arc_out = arc_out.clone();
37          thread::spawn(move || {
38
39               arc_out.lock_fn(|mut lock| {
40                    lock.write_fmt(format_args!("#@{} {}\n", num_thread, "Thread #OK")).unwrap();
41                    lock.write_fmt(format_args!("#@{} {}\n", num_thread, "Thread #T")).unwrap();
42               });
43
44               barrier.wait();
45          });
46     }
47
48     barrier.wait();
49
50     arc_out.write_fmt(format_args!("#@{} {}\n", 999, "Thread pull end.")).unwrap();
51     //Arc<UnionWrite>, auto lock methods.
52
53     // /tmp/file.out+
54     // /tmp/file.out+
55}

Implementors§