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:
BlockIo
KnownLength
BlockReader
andBlockWriter
ByteReader
andByteWriter
- [
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 theLockable
lock 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
sourceimpl<'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>,
sourcefn block_size(&self) -> usize
fn block_size(&self) -> usize
Returns the size in bytes of a single block (i.e., sector), the minimum granularity of I/O transfers. Read more
sourceimpl<'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>,
sourceimpl<'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>,
sourceimpl<'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>,
sourceimpl<'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>,
sourceimpl<'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>,
sourceimpl<'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>,
sourceimpl<'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>,
sourceimpl<'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>,
sourceimpl<'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,
sourceimpl<'io, IO: Debug, L: Debug, B: Debug> Debug for LockableIo<'io, IO, L, B> where
IO: 'io + ?Sized,
L: for<'a> Lockable<'a, IO> + ?Sized,
B: Borrow<L>,
impl<'io, IO: Debug, L: Debug, B: Debug> Debug for LockableIo<'io, IO, L, B> where
IO: 'io + ?Sized,
L: for<'a> Lockable<'a, IO> + ?Sized,
B: Borrow<L>,
sourceimpl<'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>,
sourceimpl<'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>,
sourceimpl<'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>,
sourceimpl<'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>,
sourcefn read(&mut self, buf: &mut [u8]) -> Result<usize>
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>
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>
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
unsafe fn initializer(&self) -> Initializer
Determines if this Read
er 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>
Read the exact number of bytes required to fill buf
. Read more
fn by_ref(&mut self) -> &mut Self
fn by_ref(&mut self) -> &mut Self
Creates a “by reference” adaptor for this instance of Read
. Read more
sourceimpl<'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>,
sourcefn read(&mut self, buf: &mut [u8]) -> Result<usize>
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>
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>
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
unsafe fn initializer(&self) -> Initializer
Determines if this Read
er 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>
Read the exact number of bytes required to fill buf
. Read more
fn by_ref(&mut self) -> &mut Self
fn by_ref(&mut self) -> &mut Self
Creates a “by reference” adaptor for this instance of Read
. Read more
sourceimpl<'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>,
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>,
sourcefn seek(&mut self, position: SeekFrom) -> Result<u64>
fn seek(&mut self, position: SeekFrom) -> Result<u64>
Seek to an offset, in bytes, in a stream. Read more
fn stream_len(&mut self) -> Result<u64, Error>
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>
fn stream_position(&mut self) -> Result<u64, Error>
Returns the current seek position from the start of the stream. Read more
sourceimpl<'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>,
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>,
sourcefn seek(&mut self, position: SeekFrom) -> Result<u64>
fn seek(&mut self, position: SeekFrom) -> Result<u64>
Seek to an offset, in bytes, in a stream. Read more
fn stream_len(&mut self) -> Result<u64, Error>
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>
fn stream_position(&mut self) -> Result<u64, Error>
Returns the current seek position from the start of the stream. Read more
sourceimpl<'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>,
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>,
sourcefn write(&mut self, buf: &[u8]) -> Result<usize>
fn write(&mut self, buf: &[u8]) -> Result<usize>
Write a buffer into this writer, returning how many bytes were written. Read more
sourcefn flush(&mut self) -> Result<()>
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>
fn write_all(&mut self, buf: &[u8]) -> Result<(), Error>
Attempts to write an entire buffer into this writer. Read more
sourceimpl<'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>,
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>,
sourceimpl<'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>,
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>,
sourcefn write(&mut self, buf: &[u8]) -> Result<usize>
fn write(&mut self, buf: &[u8]) -> Result<usize>
Write a buffer into this writer, returning how many bytes were written. Read more
sourcefn flush(&mut self) -> Result<()>
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>
fn write_all(&mut self, buf: &[u8]) -> Result<(), Error>
Attempts to write an entire buffer into this writer. Read more
sourceimpl<'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>,
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>,
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
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
sourceimpl<T> ToOwned for T where
T: Clone,
impl<T> ToOwned for T where
T: Clone,
type Owned = T
type Owned = T
The resulting type after obtaining ownership.
sourcefn clone_into(&self, target: &mut T)
fn clone_into(&self, target: &mut T)
toowned_clone_into
)Uses borrowed data to replace owned data, usually by cloning. Read more