[−][src]Struct glommio::io::DmaStreamReader
Provides linear access to a DmaFile
. The DmaFile
is a convenient way to
manage a file through Direct I/O, but its interface is conductive to random access,
as a position must always be specified.
In situations where the file must be scanned linearly - either because a large chunk is to be read or because we are scanning the whole file, it may be more convenient to use a linear scan API.
The DmaStreamReader
implements AsyncRead
, which can offer the user with a convenient
way of issuing reads. However note that this mandates a copy between the Dma Buffer used
to read the file contents and the user-specified buffer.
To avoid that copy the DmaStreamReader
provides the get_buffer_aligned
method which
exposes the buffer as a byte slice. Different situations will call for different APIs to
be used.
Implementations
impl DmaStreamReader
[src]
pub async fn close(self) -> Result<()>
[src]
Closes this DmaStreamReader
.
It is illegal to close the DmaStreamReader
more than once.
Examples
use glommio::io::{DmaFile, DmaStreamReaderBuilder}; use glommio::LocalExecutor; let ex = LocalExecutor::make_default(); ex.run(async { let file = DmaFile::open("myfile.txt").await.unwrap(); let mut reader = DmaStreamReaderBuilder::new(file).build(); reader.close().await.unwrap(); });
pub fn skip(&mut self, bytes: u64)
[src]
Skip reading bytes from this DmaStreamReader
.
The file cursor is advanced by the provided bytes. As this is a linear access API, once those bytes are skipped they are gone. If you need to read those bytes, just not now, it is better to read them and save them in some temporary buffer.
Examples
use glommio::io::{DmaFile, DmaStreamReaderBuilder}; use glommio::LocalExecutor; let ex = LocalExecutor::make_default(); ex.run(async { let file = DmaFile::open("myfile.txt").await.unwrap(); let mut reader = DmaStreamReaderBuilder::new(file).build(); assert_eq!(reader.current_pos(), 0); reader.skip(8); assert_eq!(reader.current_pos(), 8); reader.close().await.unwrap(); });
pub fn current_pos(&self) -> u64
[src]
Acquires the current position of this DmaStreamReader
.
Examples
use glommio::io::{DmaFile, DmaStreamReaderBuilder}; use glommio::LocalExecutor; let ex = LocalExecutor::make_default(); ex.run(async { let file = DmaFile::open("myfile.txt").await.unwrap(); let mut reader = DmaStreamReaderBuilder::new(file).build(); assert_eq!(reader.current_pos(), 0); reader.skip(8); assert_eq!(reader.current_pos(), 8); reader.close().await.unwrap(); });
pub async fn get_buffer_aligned<'_>(
&'_ mut self,
len: u64
) -> Result<ReadResult>
[src]
&'_ mut self,
len: u64
) -> Result<ReadResult>
Allows access to the buffer that holds the current position with no extra copy
In order to use this API, one must guarantee that reading the specified length may cross
into a different buffer. Users of this API are expected to be aware of their buffer size
(selectable in the DmaStreamReaderBuilder
) and act accordingly.
The buffer is also not released until the returned ReadResult
goes out of scope. So
if you plan to keep this alive for a long time this is probably the wrong API.
Let's say you want to open a file and check if its header is sane: this is a good API for that.
But if after such header there is an index that you want to keep in memory, then you
are probably better off with one of the methods from AsyncReadExt
.
Examples
use glommio::io::{DmaFile, DmaStreamReaderBuilder}; use glommio::LocalExecutor; let ex = LocalExecutor::make_default(); ex.run(async { let file = DmaFile::open("myfile.txt").await.unwrap(); let mut reader = DmaStreamReaderBuilder::new(file).build(); assert_eq!(reader.current_pos(), 0); let result = reader.get_buffer_aligned(512).await.unwrap(); assert_eq!(result.len(), 512); println!("First 512 bytes: {:?}", result.as_bytes()); reader.close().await.unwrap(); });
Trait Implementations
impl AsyncRead for DmaStreamReader
[src]
fn poll_read(
self: Pin<&mut Self>,
cx: &mut Context<'_>,
buf: &mut [u8]
) -> Poll<Result<usize>>
[src]
self: Pin<&mut Self>,
cx: &mut Context<'_>,
buf: &mut [u8]
) -> Poll<Result<usize>>
fn poll_read_vectored(
self: Pin<&mut Self>,
cx: &mut Context<'_>,
bufs: &mut [IoSliceMut<'_>]
) -> Poll<Result<usize, Error>>
[src]
self: Pin<&mut Self>,
cx: &mut Context<'_>,
bufs: &mut [IoSliceMut<'_>]
) -> Poll<Result<usize, Error>>
impl Debug for DmaStreamReader
[src]
Auto Trait Implementations
impl !RefUnwindSafe for DmaStreamReader
impl !Send for DmaStreamReader
impl !Sync for DmaStreamReader
impl Unpin for DmaStreamReader
impl !UnwindSafe for DmaStreamReader
Blanket Implementations
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<R> AsyncReadExt for R where
R: AsyncRead + ?Sized,
[src]
R: AsyncRead + ?Sized,
fn read(&'a mut self, buf: &'a mut [u8]) -> ReadFuture<'a, Self> where
Self: Unpin,
[src]
Self: Unpin,
fn read_vectored(
&'a mut self,
bufs: &'a mut [IoSliceMut<'a>]
) -> ReadVectoredFuture<'a, Self> where
Self: Unpin,
[src]
&'a mut self,
bufs: &'a mut [IoSliceMut<'a>]
) -> ReadVectoredFuture<'a, Self> where
Self: Unpin,
fn read_to_end(&'a mut self, buf: &'a mut Vec<u8>) -> ReadToEndFuture<'a, Self> where
Self: Unpin,
[src]
Self: Unpin,
fn read_to_string(
&'a mut self,
buf: &'a mut String
) -> ReadToStringFuture<'a, Self> where
Self: Unpin,
[src]
&'a mut self,
buf: &'a mut String
) -> ReadToStringFuture<'a, Self> where
Self: Unpin,
fn read_exact(&'a mut self, buf: &'a mut [u8]) -> ReadExactFuture<'a, Self> where
Self: Unpin,
[src]
Self: Unpin,
fn take(self, limit: u64) -> Take<Self>
[src]
fn bytes(self) -> Bytes<Self>
[src]
fn chain<R>(self, next: R) -> Chain<Self, R> where
R: AsyncRead,
[src]
R: AsyncRead,
fn boxed_reader<'a>(self) -> Pin<Box<dyn AsyncRead + 'a + Send>> where
Self: Send + 'a,
[src]
Self: Send + 'a,
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
pub fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> From<T> for T
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T> Same<T> for T
[src]
type Output = T
Should always be Self
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
pub fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,