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:
BlockIoKnownLengthBlockReaderandBlockWriterByteReaderandByteWriter- [
core2::io::Read], [core2::io::Write], and [core2::io::Seek] core::fmt::Write
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:
L: the type of the lock itself, which implementsLockable.IO, the inner type inside of theLockablelock typeL.
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>,
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
fn block_size(&self) -> usize
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>,
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§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>,
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§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>,
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§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>,
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§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>,
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§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>,
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§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>,
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§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>,
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§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,
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§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,
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§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>,
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>,
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>,
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§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>,
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§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>,
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>
fn read(&mut self, buf: &mut [u8]) -> Result<usize>
§fn read_to_end(&mut self, buf: &mut Vec<u8, Global>) -> Result<usize, Error>
fn read_to_end(&mut self, buf: &mut Vec<u8, Global>) -> Result<usize, Error>
buf. Read more§fn read_to_string(&mut self, buf: &mut String) -> Result<usize, Error>
fn read_to_string(&mut self, buf: &mut String) -> Result<usize, Error>
buf. Read more§unsafe fn initializer(&self) -> Initializer
unsafe fn initializer(&self) -> Initializer
Reader can work with buffers of uninitialized
memory. Read more§fn read_exact(&mut self, buf: &mut [u8]) -> Result<(), Error>
fn read_exact(&mut self, buf: &mut [u8]) -> Result<(), Error>
buf. Read more§fn by_ref(&mut self) -> &mut Selfwhere
Self: Sized,
fn by_ref(&mut self) -> &mut Selfwhere Self: Sized,
Read. Read moresource§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>,
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>
fn read(&mut self, buf: &mut [u8]) -> Result<usize>
§fn read_to_end(&mut self, buf: &mut Vec<u8, Global>) -> Result<usize, Error>
fn read_to_end(&mut self, buf: &mut Vec<u8, Global>) -> Result<usize, Error>
buf. Read more§fn read_to_string(&mut self, buf: &mut String) -> Result<usize, Error>
fn read_to_string(&mut self, buf: &mut String) -> Result<usize, Error>
buf. Read more§unsafe fn initializer(&self) -> Initializer
unsafe fn initializer(&self) -> Initializer
Reader can work with buffers of uninitialized
memory. Read more§fn read_exact(&mut self, buf: &mut [u8]) -> Result<(), Error>
fn read_exact(&mut self, buf: &mut [u8]) -> Result<(), Error>
buf. Read more§fn by_ref(&mut self) -> &mut Selfwhere
Self: Sized,
fn by_ref(&mut self) -> &mut Selfwhere Self: Sized,
Read. Read more