Trait glommio::ByteSliceMutExt [−][src]
pub trait ByteSliceMutExt { fn write_at<S: AsRef<[u8]> + ?Sized>(
&mut self,
offset: usize,
src: &S
) -> usize; fn memset(&mut self, value: u8); }
Expand description
Utility methods for working with mutable byte slices/buffers.
Required methods
Writes data to this buffer from a user-provided byte slice, starting at a particular offset
Returns
The amount of bytes written.
Examples
use glommio::{io::DmaFile, ByteSliceMutExt, LocalExecutor}; let ex = LocalExecutor::default(); ex.run(async { let file = DmaFile::create("test.txt").await.unwrap(); let mut buf = file.alloc_dma_buffer(4096); let vec = vec![1; 64]; let n = buf.write_at(0, &vec); assert_eq!(n, 64); // wrote 64 bytes. let n = buf.write_at(4090, &vec); assert_eq!(n, 6); // wrote 6 bytes, as there are only 6 bytes left from this offset file.close().await.unwrap(); });