pub struct Cursor<T, B: Buffer<T>> { /* private fields */ }
Expand description
A cursor for safely writing into an uninitialized buffer.
A Cursor
is returned from Buffer::cursor
, which provides way to
write to a Buffer
without needing to use unsafe
.
§Examples
ⓘ
let mut buf = Vec::with_capacity(256);
let mut cursor = Cursor::new(spare_capacity(&mut buf));
let _nread = read(&input, &mut cursor).unwrap();
let _nread = read(&input, &mut cursor).unwrap();
let _nread = read(&input, &mut cursor).unwrap();
let total_read = cursor.finish();
Implementations§
Source§impl<T, B: Buffer<T>> Cursor<T, B>
impl<T, B: Buffer<T>> Cursor<T, B>
Sourcepub fn write(&mut self, t: T)
pub fn write(&mut self, t: T)
Write an element to the buffer.
§Panics
Panics if this cursor has already reached the end of the buffer.
Sourcepub fn write_slice(&mut self, t: &[T])where
T: Copy,
pub fn write_slice(&mut self, t: &[T])where
T: Copy,
Write multiple elements to the buffer.
§Panics
Panics if this cursor is already within t.len()
elements of the end
of the buffer.
Trait Implementations§
Source§impl<T, B: Buffer<T>> Buffer<T> for &mut Cursor<T, B>
impl<T, B: Buffer<T>> Buffer<T> for &mut Cursor<T, B>
Source§fn buffer_ptr(&mut self) -> *mut T
fn buffer_ptr(&mut self) -> *mut T
Return a raw mutable pointer to the underlying buffer. Read more
Source§fn buffer_len(&self) -> usize
fn buffer_len(&self) -> usize
Return the length in elements of the underlying buffer.
Auto Trait Implementations§
impl<T, B> Freeze for Cursor<T, B>where
B: Freeze,
impl<T, B> RefUnwindSafe for Cursor<T, B>where
B: RefUnwindSafe,
T: RefUnwindSafe,
impl<T, B> Send for Cursor<T, B>
impl<T, B> Sync for Cursor<T, B>
impl<T, B> Unpin for Cursor<T, B>
impl<T, B> UnwindSafe for Cursor<T, B>where
B: UnwindSafe,
T: UnwindSafe,
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more