pub struct FlushLockWrite<'a, T: ExtWrite<'a>>(/* private fields */);Expand description
An implementation of Trait Write that calls the flush() method when removing a lock.
Implementations§
Source§impl<'a, T: ExtWrite<'a>> FlushLockWrite<'a, T>
impl<'a, T: ExtWrite<'a>> FlushLockWrite<'a, T>
Sourcepub fn new(a: T) -> Self
pub fn new(a: T) -> Self
Examples found in repository?
examples/maximum.rs (line 15)
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}More examples
examples/thread.rs (line 20)
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}Trait Implementations§
Source§impl<'a, T: ExtWrite<'a>> ExtWrite<'a> for FlushLockWrite<'a, T>
impl<'a, T: ExtWrite<'a>> ExtWrite<'a> for FlushLockWrite<'a, T>
Source§impl<'a, T: ExtWrite<'a>> From<T> for FlushLockWrite<'a, T>
impl<'a, T: ExtWrite<'a>> From<T> for FlushLockWrite<'a, T>
Source§impl<'a, T: ExtWrite<'a>> Write for FlushLockWrite<'a, T>
impl<'a, T: ExtWrite<'a>> Write for FlushLockWrite<'a, T>
Source§fn write(&mut self, buf: &[u8]) -> Result<usize>
fn write(&mut self, buf: &[u8]) -> Result<usize>
Writes a buffer into this writer, returning how many bytes were written. Read more
Source§fn flush(&mut self) -> Result<()>
fn flush(&mut self) -> Result<()>
Flushes this output stream, ensuring that all intermediately buffered
contents reach their destination. Read more
Source§fn write_all(&mut self, buf: &[u8]) -> Result<()>
fn write_all(&mut self, buf: &[u8]) -> Result<()>
Attempts to write an entire buffer into this writer. Read more
Source§fn write_fmt(&mut self, fmt: Arguments<'_>) -> Result<()>
fn write_fmt(&mut self, fmt: Arguments<'_>) -> Result<()>
Writes a formatted string into this writer, returning any error
encountered. Read more
Source§fn is_write_vectored(&self) -> bool
fn is_write_vectored(&self) -> bool
🔬This is a nightly-only experimental API. (
can_vector)Auto Trait Implementations§
impl<'a, T> Freeze for FlushLockWrite<'a, T>where
T: Freeze,
impl<'a, T> RefUnwindSafe for FlushLockWrite<'a, T>where
T: RefUnwindSafe,
impl<'a, T> Send for FlushLockWrite<'a, T>where
T: Send,
impl<'a, T> Sync for FlushLockWrite<'a, T>where
T: Sync,
impl<'a, T> Unpin for FlushLockWrite<'a, T>where
T: Unpin,
impl<'a, T> UnwindSafe for FlushLockWrite<'a, T>where
T: UnwindSafe,
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more