std_lock/
std_lock.rs

1
2extern crate cluExtIO;
3
4use std::io::Error;
5use cluExtIO::ExtWrite;
6use std::io::Write;
7
8pub fn main() -> Result<(), Error> {
9
10     let out = std::io::stdout();
11
12     my_function(&out, 0, "No eND:)")?;
13     
14     out.lock_fn(|mut l| {
15          l.write(b"End.\n")
16     })?;
17
18     Ok( () )
19}
20
21fn my_function<'a, W: ExtWrite<'a>>(raw_write: &'a W, n: usize, str: &'static str) -> Result<(), std::io::Error> {
22     let mut lock = raw_write.lock();
23
24     lock.write_fmt(format_args!("#@{} {}\n", n, "Test"))?;
25     lock.write_fmt(format_args!("#@{} {}\n", n+1, "MyString"))?;
26
27     lock.write_fmt(format_args!("#@{} ~{}\n", n+2, str))
28}