Trait glommio::ByteSliceExt[][src]

pub trait ByteSliceExt {
    fn read_at<D: AsMut<[u8]> + ?Sized>(
        &self,
        offset: usize,
        destination: &mut D
    ) -> usize; }
Expand description

Utility methods for working with byte slices/buffers.

Required methods

Copies the contents of self into the byte-slice destination.

The copy starts at position offset into the source and copies as many bytes as possible until either we don’t have more bytes to copy or destination doesn’t have more space to hold them.

Returns

The amount of bytes written.

Examples

use glommio::{io::DmaFile, ByteSliceExt, LocalExecutor};

let ex = LocalExecutor::default();
ex.run(async {
    let file = DmaFile::create("test.txt").await.unwrap();
    let buf = file.alloc_dma_buffer(4096);
    let mut vec = vec![0; 64];
    let n = buf.read_at(0, &mut vec);
    assert_eq!(n, 64); // read 64 bytes, the size of the buffer

    let n = buf.read_at(4090, &mut vec);
    assert_eq!(n, 6); // read 6 bytes, as there are only 6 bytes left from this offset
    file.close().await.unwrap();
});

Implementors