pub struct BinaryBuffer<T>(/* private fields */);Implementations§
Source§impl BinaryBuffer<Vec<u8>>
impl BinaryBuffer<Vec<u8>>
pub fn new() -> Self
pub fn with_capacity(capacity: usize) -> Self
pub fn into_inner(self) -> Vec<u8> ⓘ
Source§impl<T: AsRef<[u8]>> BinaryBuffer<T>
impl<T: AsRef<[u8]>> BinaryBuffer<T>
pub fn from_data(data: T) -> Self
pub fn read_string(&mut self) -> Result<String>
pub fn read_nullable_string(&mut self) -> Result<Option<String>>
pub fn read_json<V: DeserializeOwned>(&mut self) -> Result<V>
Methods from Deref<Target = Cursor<T>>§
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<T> Deref for BinaryBuffer<T>
impl<T> Deref for BinaryBuffer<T>
Auto Trait Implementations§
impl<T> Freeze for BinaryBuffer<T>where
T: Freeze,
impl<T> RefUnwindSafe for BinaryBuffer<T>where
T: RefUnwindSafe,
impl<T> Send for BinaryBuffer<T>where
T: Send,
impl<T> Sync for BinaryBuffer<T>where
T: Sync,
impl<T> Unpin for BinaryBuffer<T>where
T: Unpin,
impl<T> UnsafeUnpin for BinaryBuffer<T>where
T: UnsafeUnpin,
impl<T> UnwindSafe for BinaryBuffer<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
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> Declassify for T
impl<T> Declassify for T
type Declassified = T
fn declassify(self) -> T
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more