pub struct CursorBytesPtr(/* private fields */);Expand description
A (safe) wrapper over a raw pointer to Cursor<Bytes>
Methods from Deref<Target = Cursor<Bytes>>§
1.0.0 · Sourcepub fn get_ref(&self) -> &T
pub fn get_ref(&self) -> &T
Gets a reference to the underlying value in this cursor.
§Examples
use std::io::Cursor;
let buff = Cursor::new(Vec::new());
let reference = buff.get_ref();1.0.0 · Sourcepub fn get_mut(&mut self) -> &mut T
pub fn get_mut(&mut self) -> &mut T
Gets a mutable reference to the underlying value in this cursor.
Care should be taken to avoid modifying the internal I/O state of the underlying value as it may corrupt this cursor’s position.
§Examples
use std::io::Cursor;
let mut buff = Cursor::new(Vec::new());
let reference = buff.get_mut();1.0.0 · Sourcepub fn position(&self) -> u64
pub fn position(&self) -> u64
Returns the current position of this cursor.
§Examples
use std::io::Cursor;
use std::io::prelude::*;
use std::io::SeekFrom;
let mut buff = Cursor::new(vec![1, 2, 3, 4, 5]);
assert_eq!(buff.position(), 0);
buff.seek(SeekFrom::Current(2)).unwrap();
assert_eq!(buff.position(), 2);
buff.seek(SeekFrom::Current(-1)).unwrap();
assert_eq!(buff.position(), 1);1.0.0 · Sourcepub fn set_position(&mut self, pos: u64)
pub fn set_position(&mut self, pos: u64)
Sets the position of this cursor.
§Examples
use std::io::Cursor;
let mut buff = Cursor::new(vec![1, 2, 3, 4, 5]);
assert_eq!(buff.position(), 0);
buff.set_position(2);
assert_eq!(buff.position(), 2);
buff.set_position(4);
assert_eq!(buff.position(), 4);Sourcepub fn split(&self) -> (&[u8], &[u8])
🔬This is a nightly-only experimental API. (cursor_split)
pub fn split(&self) -> (&[u8], &[u8])
cursor_split)Splits the underlying slice at the cursor position and returns them.
§Examples
#![feature(cursor_split)]
use std::io::Cursor;
let mut buff = Cursor::new(vec![1, 2, 3, 4, 5]);
assert_eq!(buff.split(), ([].as_slice(), [1, 2, 3, 4, 5].as_slice()));
buff.set_position(2);
assert_eq!(buff.split(), ([1, 2].as_slice(), [3, 4, 5].as_slice()));
buff.set_position(6);
assert_eq!(buff.split(), ([1, 2, 3, 4, 5].as_slice(), [].as_slice()));Sourcepub fn split_mut(&mut self) -> (&mut [u8], &mut [u8])
🔬This is a nightly-only experimental API. (cursor_split)
pub fn split_mut(&mut self) -> (&mut [u8], &mut [u8])
cursor_split)Splits the underlying slice at the cursor position and returns them mutably.
§Examples
#![feature(cursor_split)]
use std::io::Cursor;
let mut buff = Cursor::new(vec![1, 2, 3, 4, 5]);
assert_eq!(buff.split_mut(), ([].as_mut_slice(), [1, 2, 3, 4, 5].as_mut_slice()));
buff.set_position(2);
assert_eq!(buff.split_mut(), ([1, 2].as_mut_slice(), [3, 4, 5].as_mut_slice()));
buff.set_position(6);
assert_eq!(buff.split_mut(), ([1, 2, 3, 4, 5].as_mut_slice(), [].as_mut_slice()));Trait Implementations§
Source§impl Debug for CursorBytesPtr
impl Debug for CursorBytesPtr
Source§impl Deref for CursorBytesPtr
impl Deref for CursorBytesPtr
Source§impl DerefMut for CursorBytesPtr
impl DerefMut for CursorBytesPtr
Auto Trait Implementations§
impl Freeze for CursorBytesPtr
impl RefUnwindSafe for CursorBytesPtr
impl Send for CursorBytesPtr
impl Sync for CursorBytesPtr
impl Unpin for CursorBytesPtr
impl UnwindSafe for CursorBytesPtr
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