FlushLockWrite

Struct FlushLockWrite 

Source
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>

Source

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
Hide additional 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> + Clone> Clone for FlushLockWrite<'a, T>

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<'a, T: Debug + ExtWrite<'a>> Debug for FlushLockWrite<'a, T>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<'a, T: ExtWrite<'a>> ExtWrite<'a> for FlushLockWrite<'a, T>

Source§

type LockWrite = FlushDropWrite<<T as ExtWrite<'a>>::LockWrite>

Source§

fn lock(&'a self) -> Self::LockWrite

Blocking the output stream.
Source§

fn lock_fn<F: FnMut(Self::LockWrite) -> R, R>(&'a self, f: F) -> R

Alternative method of blocking the output stream using the closure.
Source§

impl<'a, T: ExtWrite<'a>> From<T> for FlushLockWrite<'a, T>

Source§

fn from(a: T) -> Self

Converts to this type from the input type.
Source§

impl<'a, T: ExtWrite<'a>> Write for FlushLockWrite<'a, T>

Source§

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<()>

Flushes this output stream, ensuring that all intermediately buffered contents reach their destination. Read more
Source§

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<()>

Writes a formatted string into this writer, returning any error encountered. Read more
1.36.0 · Source§

fn write_vectored(&mut self, bufs: &[IoSlice<'_>]) -> Result<usize, Error>

Like write, except that it writes from a slice of buffers. Read more
Source§

fn is_write_vectored(&self) -> bool

🔬This is a nightly-only experimental API. (can_vector)
Determines if this Writer has an efficient write_vectored implementation. Read more
Source§

fn write_all_vectored(&mut self, bufs: &mut [IoSlice<'_>]) -> Result<(), Error>

🔬This is a nightly-only experimental API. (write_all_vectored)
Attempts to write multiple buffers into this writer. Read more
1.0.0 · Source§

fn by_ref(&mut self) -> &mut Self
where Self: Sized,

Creates a “by reference” adapter for this instance of Write. Read more

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> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<'a, E> ImMutWrite<'a> for E
where E: ExtWrite<'a>,

Source§

fn write(&'a self, buf: &[u8]) -> Result<usize, Error>

Source§

fn flush(&'a self) -> Result<(), Error>

Source§

fn write_all(&'a self, buf: &[u8]) -> Result<(), Error>

Source§

fn write_fmt(&'a self, fmt: Arguments<'_>) -> Result<(), Error>

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> UnionWriteConst for T
where T: Write,

Source§

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