pub struct Buffer<'a>(/* private fields */);
Expand description
Buffer is a read-write buffer that can be used for I/O with the block device. They are created by a BufferAllocator, and automatically deallocate themselves when they go out of scope.
Most usage will be on the unowned BufferRef and MutableBufferRef types, since these types are used for Device::read and Device::write.
Buffers are always block-aligned (both in offset and length), but unaligned slices can be made with the reference types. That said, the Device trait requires aligned BufferRef and MutableBufferRef objects, so alignment must be restored by the time a device read/write is requested.
For example, when writing an unaligned amount of data to the device, generally two Buffers would need to be involved; the input Buffer could be used to write everything up to the last block, and a second single-block alignment Buffer would be used to read-modify-update the last block.
Implementations§
Source§impl<'a> Buffer<'a>
impl<'a> Buffer<'a>
Sourcepub fn subslice<R: SliceRange>(&self, range: R) -> BufferRef<'_>
pub fn subslice<R: SliceRange>(&self, range: R) -> BufferRef<'_>
Takes a read-only reference to this buffer over |range| (which must be within the size of the buffer).
Sourcepub fn as_mut(&mut self) -> MutableBufferRef<'_>
pub fn as_mut(&mut self) -> MutableBufferRef<'_>
Takes a read-write reference to this buffer.
Sourcepub fn subslice_mut<R: SliceRange>(&mut self, range: R) -> MutableBufferRef<'_>
pub fn subslice_mut<R: SliceRange>(&mut self, range: R) -> MutableBufferRef<'_>
Takes a read-write reference to this buffer over |range| (which must be within the size of the buffer).
Sourcepub fn as_mut_slice(&mut self) -> &mut [u8] ⓘ
pub fn as_mut_slice(&mut self) -> &mut [u8] ⓘ
Returns a mutable slice of the buffer’s contents.
Sourcepub fn range(&self) -> Range<usize>
pub fn range(&self) -> Range<usize>
Returns the range in the underlying BufferSource that this buffer covers.
Sourcepub fn allocator(&self) -> &BufferAllocator
pub fn allocator(&self) -> &BufferAllocator
Returns a reference to the allocator.