pub struct LockableIo<'io, IO, L, B> where
    IO: 'io + ?Sized,
    L: for<'a> Lockable<'a, IO> + ?Sized,
    B: Borrow<L>, 
{ /* private fields */ }
Expand description

A struct that holds an IO object wrapped in a Lockable type L, for the purpose of forwarding various IO-related traits through the lock to the IO type.

This allows an IO object inside of a lock type (e.g., Mutex<IO>, Arc<Mutex<IO>>) to be used as a type that implements some IO-specific trait, such as those listed in the crate-level documentation.

The following traits are forwarded to the IO instance through the Lockable wrapper:

Usage and Examples

The Rust compiler has difficulty inferring all of the types needed in this struct; therefore, you must typically specify at least two types:

  1. L: the type of the lock itself, which implements Lockable.
  2. IO, the inner type inside of the Lockable lock type L.

Here’s an example of the minimal types that must be specified:

// `storage_dev` has the type `Arc<spin::Mutex<dyn Storage Device + Send>>`
let storage_dev = storage_manager::storage_devices().next().unwrap();
let fail = LockableIo::from(storage_dev); // <-- Error: rustc will complain!
let success = LockableIo::<dyn StorageDevice + Send, spin::Mutex<_>, _>::from(storage_dev);
let rw = ReaderWriter::new(ByteReaderWriterWrapper::from(success));

You can optionally specify the type IO within the Lockable type L, but Rustc can infer that once you specify the first type IO. You can also optionally specify the final parameter B: Borrow<L>, but Rustc can also infer that based on your argument to LockableIo::from(). You can ask Rustc to infer both of those using the _ character, as shown above.

Trait Implementations

Returns the size in bytes of a single block (i.e., sector), the minimum granularity of I/O transfers. Read more

Reads blocks of data from this reader into the given buffer. Read more

Reads blocks of data from this reader into the given buffer. Read more

Writes blocks of data from the given buffer to this writer. Read more

Flushes this entire writer’s output stream, ensuring all contents in intermediate buffers are fully written out. Read more

Writes blocks of data from the given buffer to this writer. Read more

Flushes this entire writer’s output stream, ensuring all contents in intermediate buffers are fully written out. Read more

Reads bytes of data from this reader into the given buffer. Read more

Reads bytes of data from this reader into the given buffer. Read more

Writes bytes of data from the given buffer to this writer. Read more

Flushes this writer’s output stream, ensuring all contents in intermediate buffers are fully written out. Read more

Writes bytes of data from the given buffer to this writer. Read more

Flushes this writer’s output stream, ensuring all contents in intermediate buffers are fully written out. Read more

Returns a copy of the value. Read more

Performs copy-assignment from source. Read more

Formats the value using the given formatter. Read more

The resulting type after dereferencing.

Dereferences the value.

Converts to this type from the input type.

Returns the length (size in bytes) of this I/O stream or device.

Pull some bytes from this source into the specified buffer, returning how many bytes were read. Read more

Read all bytes until EOF in this source, placing them into buf. Read more

Read all bytes until EOF in this source, appending them to buf. Read more

Determines if this Reader can work with buffers of uninitialized memory. Read more

Read the exact number of bytes required to fill buf. Read more

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

Transforms this Read instance to an Iterator over its bytes. Read more

Creates an adaptor which will chain this stream with another. Read more

Creates an adaptor which will read at most limit bytes from it. Read more

Pull some bytes from this source into the specified buffer, returning how many bytes were read. Read more

Read all bytes until EOF in this source, placing them into buf. Read more

Read all bytes until EOF in this source, appending them to buf. Read more

Determines if this Reader can work with buffers of uninitialized memory. Read more

Read the exact number of bytes required to fill buf. Read more

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

Transforms this Read instance to an Iterator over its bytes. Read more

Creates an adaptor which will chain this stream with another. Read more

Creates an adaptor which will read at most limit bytes from it. Read more

Seek to an offset, in bytes, in a stream. Read more

Rewind to the beginning of a stream. Read more

Returns the length of this stream (in bytes). Read more

Returns the current seek position from the start of the stream. Read more

Seek to an offset, in bytes, in a stream. Read more

Rewind to the beginning of a stream. Read more

Returns the length of this stream (in bytes). Read more

Returns the current seek position from the start of the stream. Read more

Write a buffer into this writer, returning how many bytes were written. Read more

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

Attempts to write an entire buffer into this writer. Read more

Writes a formatted string into this writer, returning any error encountered. Read more

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

Writes a string slice into this writer, returning whether the write succeeded. Read more

Writes a char into this writer, returning whether the write succeeded. Read more

Glue for usage of the write! macro with implementors of this trait. Read more

Write a buffer into this writer, returning how many bytes were written. Read more

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

Attempts to write an entire buffer into this writer. Read more

Writes a formatted string into this writer, returning any error encountered. Read more

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

Writes a string slice into this writer, returning whether the write succeeded. Read more

Writes a char into this writer, returning whether the write succeeded. Read more

Glue for usage of the write! macro with implementors of this trait. Read more

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Converts to this type from the input type.

Returns the argument unchanged.

Calls U::from(self).

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

The resulting type after obtaining ownership.

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

🔬 This is a nightly-only experimental API. (toowned_clone_into)

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

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.