Struct io::LockableIo

source ·
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§

source§

impl<'io, IO, L, B> BlockIo for LockableIo<'io, IO, L, B>where IO: BlockIo + 'io + ?Sized, L: for<'a> Lockable<'a, IO> + ?Sized, B: Borrow<L>,

source§

fn block_size(&self) -> usize

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

impl<'io, IO, L, B> BlockReader for &LockableIo<'io, IO, L, B>where IO: BlockReader + 'io + ?Sized, L: for<'a> Lockable<'a, IO> + ?Sized, B: Borrow<L>,

source§

fn read_blocks( &mut self, buffer: &mut [u8], block_offset: usize ) -> Result<usize, IoError>

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

impl<'io, IO, L, B> BlockReader for LockableIo<'io, IO, L, B>where IO: BlockReader + 'io + ?Sized, L: for<'a> Lockable<'a, IO> + ?Sized, B: Borrow<L>,

source§

fn read_blocks( &mut self, buffer: &mut [u8], block_offset: usize ) -> Result<usize, IoError>

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

impl<'io, IO, L, B> BlockWriter for &LockableIo<'io, IO, L, B>where IO: BlockWriter + 'io + ?Sized, L: for<'a> Lockable<'a, IO> + ?Sized, B: Borrow<L>,

source§

fn write_blocks( &mut self, buffer: &[u8], block_offset: usize ) -> Result<usize, IoError>

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

fn flush(&mut self) -> Result<(), IoError>

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

impl<'io, IO, L, B> BlockWriter for LockableIo<'io, IO, L, B>where IO: BlockWriter + 'io + ?Sized, L: for<'a> Lockable<'a, IO> + ?Sized, B: Borrow<L>,

source§

fn write_blocks( &mut self, buffer: &[u8], block_offset: usize ) -> Result<usize, IoError>

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

fn flush(&mut self) -> Result<(), IoError>

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

impl<'io, IO, L, B> ByteReader for &LockableIo<'io, IO, L, B>where IO: ByteReader + 'io + ?Sized, L: for<'a> Lockable<'a, IO> + ?Sized, B: Borrow<L>,

source§

fn read_at( &mut self, buffer: &mut [u8], offset: usize ) -> Result<usize, IoError>

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

impl<'io, IO, L, B> ByteReader for LockableIo<'io, IO, L, B>where IO: ByteReader + 'io + ?Sized, L: for<'a> Lockable<'a, IO> + ?Sized, B: Borrow<L>,

source§

fn read_at( &mut self, buffer: &mut [u8], offset: usize ) -> Result<usize, IoError>

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

impl<'io, IO, L, B> ByteWriter for &LockableIo<'io, IO, L, B>where IO: ByteWriter + 'io + ?Sized, L: for<'a> Lockable<'a, IO> + ?Sized, B: Borrow<L>,

source§

fn write_at(&mut self, buffer: &[u8], offset: usize) -> Result<usize, IoError>

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

fn flush(&mut self) -> Result<(), IoError>

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

impl<'io, IO, L, B> ByteWriter for LockableIo<'io, IO, L, B>where IO: ByteWriter + 'io + ?Sized, L: for<'a> Lockable<'a, IO> + ?Sized, B: Borrow<L>,

source§

fn write_at(&mut self, buffer: &[u8], offset: usize) -> Result<usize, IoError>

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

fn flush(&mut self) -> Result<(), IoError>

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

impl<'io, IO, L, B> Clone for LockableIo<'io, IO, L, B>where IO: 'io + ?Sized, L: for<'a> Lockable<'a, IO> + ?Sized, B: Borrow<L> + Clone,

source§

fn clone(&self) -> Self

Returns a copy 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<'io, IO, L, B> Debug for LockableIo<'io, IO, L, B>where IO: 'io + ?Sized + Debug, L: for<'a> Lockable<'a, IO> + ?Sized + Debug, B: Borrow<L> + Debug,

source§

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

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

impl<'io, IO, L, B> Deref for LockableIo<'io, IO, L, B>where IO: 'io + ?Sized, L: for<'a> Lockable<'a, IO> + ?Sized, B: Borrow<L>,

§

type Target = L

The resulting type after dereferencing.
source§

fn deref(&self) -> &L

Dereferences the value.
source§

impl<'io, IO, L, B> From<B> for LockableIo<'io, IO, L, B>where IO: 'io + ?Sized, L: for<'a> Lockable<'a, IO> + ?Sized, B: Borrow<L>,

source§

fn from(lockable_io: B) -> Self

Converts to this type from the input type.
source§

impl<'io, IO, L, B> KnownLength for LockableIo<'io, IO, L, B>where IO: KnownLength + 'io + ?Sized, L: for<'a> Lockable<'a, IO> + ?Sized, B: Borrow<L>,

source§

fn len(&self) -> usize

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

impl<'io, IO, L, B> Read for &LockableIo<'io, IO, L, B>where IO: Read + 'io + ?Sized, L: for<'a> Lockable<'a, IO> + ?Sized, B: Borrow<L>,

source§

fn read(&mut self, buf: &mut [u8]) -> Result<usize>

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

fn read_to_end(&mut self, buf: &mut Vec<u8, Global>) -> Result<usize, Error>

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

fn read_to_string(&mut self, buf: &mut String) -> Result<usize, Error>

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

unsafe fn initializer(&self) -> Initializer

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

fn read_exact(&mut self, buf: &mut [u8]) -> Result<(), Error>

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

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

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

fn bytes(self) -> Bytes<Self>where Self: Sized,

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

fn chain<R>(self, next: R) -> Chain<Self, R>where R: Read, Self: Sized,

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

fn take(self, limit: u64) -> Take<Self>where Self: Sized,

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

impl<'io, IO, L, B> Read for LockableIo<'io, IO, L, B>where IO: Read + 'io + ?Sized, L: for<'a> Lockable<'a, IO> + ?Sized, B: Borrow<L>,

source§

fn read(&mut self, buf: &mut [u8]) -> Result<usize>

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

fn read_to_end(&mut self, buf: &mut Vec<u8, Global>) -> Result<usize, Error>

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

fn read_to_string(&mut self, buf: &mut String) -> Result<usize, Error>

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

unsafe fn initializer(&self) -> Initializer

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

fn read_exact(&mut self, buf: &mut [u8]) -> Result<(), Error>

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

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

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

fn bytes(self) -> Bytes<Self>where Self: Sized,

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

fn chain<R>(self, next: R) -> Chain<Self, R>where R: Read, Self: Sized,

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

fn take(self, limit: u64) -> Take<Self>where Self: Sized,

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

impl<'io, IO, L, B> Seek for &LockableIo<'io, IO, L, B>where IO: Seek + 'io + ?Sized, L: for<'a> Lockable<'a, IO> + ?Sized, B: Borrow<L>,

source§

fn seek(&mut self, position: SeekFrom) -> Result<u64>

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

fn rewind(&mut self) -> Result<(), Error>

Rewind to the beginning of a stream. Read more
§

fn stream_len(&mut self) -> Result<u64, Error>

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

fn stream_position(&mut self) -> Result<u64, Error>

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

impl<'io, IO, L, B> Seek for LockableIo<'io, IO, L, B>where IO: Seek + 'io + ?Sized, L: for<'a> Lockable<'a, IO> + ?Sized, B: Borrow<L>,

source§

fn seek(&mut self, position: SeekFrom) -> Result<u64>

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

fn rewind(&mut self) -> Result<(), Error>

Rewind to the beginning of a stream. Read more
§

fn stream_len(&mut self) -> Result<u64, Error>

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

fn stream_position(&mut self) -> Result<u64, Error>

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

impl<'io, IO, L, B> Write for &LockableIo<'io, IO, L, B>where IO: Write + 'io + ?Sized, L: for<'a> Lockable<'a, IO> + ?Sized, B: Borrow<L>,

source§

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

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

fn flush(&mut self) -> Result<()>

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

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

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

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

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

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

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

impl<'io, IO, L, B> Write for &LockableIo<'io, IO, L, B>where IO: Write + 'io + ?Sized, L: for<'a> Lockable<'a, IO> + ?Sized, B: Borrow<L>,

source§

fn write_str(&mut self, s: &str) -> Result

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

fn write_char(&mut self, c: char) -> Result<(), Error>

Writes a char into this writer, returning whether the write succeeded. Read more
1.0.0 · source§

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

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

impl<'io, IO, L, B> Write for LockableIo<'io, IO, L, B>where IO: Write + 'io + ?Sized, L: for<'a> Lockable<'a, IO> + ?Sized, B: Borrow<L>,

source§

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

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

fn flush(&mut self) -> Result<()>

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

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

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

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

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

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

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

impl<'io, IO, L, B> Write for LockableIo<'io, IO, L, B>where IO: Write + 'io + ?Sized, L: for<'a> Lockable<'a, IO> + ?Sized, B: Borrow<L>,

source§

fn write_str(&mut self, s: &str) -> Result

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

fn write_char(&mut self, c: char) -> Result<(), Error>

Writes a char into this writer, returning whether the write succeeded. Read more
1.0.0 · source§

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

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

Auto Trait Implementations§

§

impl<'io, IO, L, B> !RefUnwindSafe for LockableIo<'io, IO, L, B>

§

impl<'io, IO: ?Sized, L: ?Sized, B> Send for LockableIo<'io, IO, L, B>where B: Send, L: Send,

§

impl<'io, IO: ?Sized, L: ?Sized, B> Sync for LockableIo<'io, IO, L, B>where B: Sync, L: Sync,

§

impl<'io, IO, L, B> !Unpin for LockableIo<'io, IO, L, B>

§

impl<'io, IO, L, B> !UnwindSafe for LockableIo<'io, IO, L, B>

Blanket Implementations§

source§

impl<T> Any for Twhere T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

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

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

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

source§

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

Mutably borrows from an owned value. Read more
source§

impl<T> From<!> for T

source§

fn from(t: !) -> T

Converts to this type from the input type.
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for Twhere 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 Twhere T: Clone,

§

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 Twhere U: Into<T>,

§

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 Twhere U: TryFrom<T>,

§

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.