pub struct Cursor<T> { /* private fields */ }
Expand description
This data structure is used as a workaround for current design of ToBytes
which does not allow multiple writes to &mut [u8]
.
Implementations§
Source§impl<T> Cursor<T>
impl<T> Cursor<T>
Sourcepub fn new(inner: T) -> Self
pub fn new(inner: T) -> Self
Creates a new cursor wrapping the provided underlying in-memory buffer.
Cursor initial position is 0
even if underlying buffer (e.g., Vec
)
is not empty. So writing to cursor starts with overwriting Vec
content, not with appending to it.
§Examples
use ark_std::io::Cursor;
let buff = Cursor::new(Vec::new());
Sourcepub fn into_inner(self) -> T
pub fn into_inner(self) -> T
Consumes this cursor, returning the underlying value.
§Examples
use ark_std::io::Cursor;
let buff = Cursor::new(Vec::new());
let vec = buff.into_inner();
Sourcepub fn get_ref(&self) -> &T
pub fn get_ref(&self) -> &T
Gets a reference to the underlying value in this cursor.
§Examples
use ark_std::io::Cursor;
let buff = Cursor::new(Vec::new());
let reference = buff.get_ref();
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 ark_std::io::Cursor;
let mut buff = Cursor::new(Vec::new());
let reference = buff.get_mut();
Sourcepub fn set_position(&mut self, pos: u64)
pub fn set_position(&mut self, pos: u64)
Sets the position of this cursor.
§Examples
use ark_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);
Trait Implementations§
Source§impl<T> Read for Cursor<T>
impl<T> Read for Cursor<T>
Source§impl Write for Cursor<&mut [u8]>
impl Write for Cursor<&mut [u8]>
Source§fn write(&mut self, buf: &[u8]) -> Result<usize>
fn write(&mut self, buf: &[u8]) -> Result<usize>
Write a buffer into this writer, returning how many bytes were written. Read more
Source§fn flush(&mut self) -> Result<()>
fn flush(&mut self) -> Result<()>
Flush this output stream, ensuring that all intermediately buffered
contents reach their destination. Read more
Source§impl Write for Cursor<Vec<u8>>
impl Write for Cursor<Vec<u8>>
Source§fn write(&mut self, buf: &[u8]) -> Result<usize>
fn write(&mut self, buf: &[u8]) -> Result<usize>
Write a buffer into this writer, returning how many bytes were written. Read more
Source§fn flush(&mut self) -> Result<()>
fn flush(&mut self) -> Result<()>
Flush this output stream, ensuring that all intermediately buffered
contents reach their destination. Read more
Auto Trait Implementations§
impl<T> Freeze for Cursor<T>where
T: Freeze,
impl<T> RefUnwindSafe for Cursor<T>where
T: RefUnwindSafe,
impl<T> Send for Cursor<T>where
T: Send,
impl<T> Sync for Cursor<T>where
T: Sync,
impl<T> Unpin for Cursor<T>where
T: Unpin,
impl<T> UnwindSafe for Cursor<T>where
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