pub trait DataSource {
Show 33 methods
// Required methods
fn available(&self) -> usize;
fn request(&mut self, count: usize) -> Result<bool>;
fn read_bytes<'a>(&mut self, buf: &'a mut [u8]) -> Result<&'a [u8]>;
fn read_utf8_to_end<'a>(&mut self, buf: &'a mut String) -> Result<&'a str>;
// Provided methods
fn require(&mut self, count: usize) -> Result { ... }
fn read_exact_bytes<'a>(&mut self, buf: &'a mut [u8]) -> Result<&'a [u8]> { ... }
fn read_array<const N: usize>(&mut self) -> Result<[u8; N]>
where Self: Sized { ... }
fn read_u8(&mut self) -> Result<u8> { ... }
fn read_i8(&mut self) -> Result<i8> { ... }
fn read_u16(&mut self) -> Result<u16> { ... }
fn read_i16(&mut self) -> Result<i16> { ... }
fn read_u16_le(&mut self) -> Result<u16> { ... }
fn read_i16_le(&mut self) -> Result<i16> { ... }
fn read_u32(&mut self) -> Result<u32> { ... }
fn read_i32(&mut self) -> Result<i32> { ... }
fn read_u32_le(&mut self) -> Result<u32> { ... }
fn read_i32_le(&mut self) -> Result<i32> { ... }
fn read_u64(&mut self) -> Result<u64> { ... }
fn read_i64(&mut self) -> Result<i64> { ... }
fn read_u64_le(&mut self) -> Result<u64> { ... }
fn read_i64_le(&mut self) -> Result<i64> { ... }
fn read_u128(&mut self) -> Result<u128> { ... }
fn read_i128(&mut self) -> Result<i128> { ... }
fn read_u128_le(&mut self) -> Result<u128> { ... }
fn read_i128_le(&mut self) -> Result<i128> { ... }
fn read_usize(&mut self) -> Result<usize> { ... }
fn read_isize(&mut self) -> Result<isize> { ... }
fn read_usize_le(&mut self) -> Result<usize> { ... }
fn read_isize_le(&mut self) -> Result<isize> { ... }
fn read_int<T: PrimInt + Pod>(&mut self) -> Result<T>
where Self: Sized { ... }
fn read_int_le<T: PrimInt + Pod>(&mut self) -> Result<T>
where Self: Sized { ... }
fn read_data<T: Pod>(&mut self) -> Result<T>
where Self: Sized { ... }
fn read_utf8<'a>(
&mut self,
count: usize,
buf: &'a mut String,
) -> Result<&'a str> { ... }
}
Expand description
A source stream of data.
Required Methods§
Sourcefn request(&mut self, count: usize) -> Result<bool>
fn request(&mut self, count: usize) -> Result<bool>
Reads at most count
bytes into an internal buffer, returning whether
enough bytes are available. To return an end-of-stream error, use require
instead.
Note that a request returning false
doesn’t necessarily mean the stream
has ended. More bytes may be read after.
Sourcefn read_bytes<'a>(&mut self, buf: &'a mut [u8]) -> Result<&'a [u8]>
fn read_bytes<'a>(&mut self, buf: &'a mut [u8]) -> Result<&'a [u8]>
Reads bytes into a slice, returning the bytes read.
Sourcefn read_utf8_to_end<'a>(&mut self, buf: &'a mut String) -> Result<&'a str>
fn read_utf8_to_end<'a>(&mut self, buf: &'a mut String) -> Result<&'a str>
Reads UTF-8 bytes into buf
until the end of the stream, returning the
string read. If invalid bytes are encountered, an error is returned and
buf
is unchanged. In this case, the stream is left in a state with an
undefined number of bytes read.
Provided Methods§
Sourcefn require(&mut self, count: usize) -> Result
fn require(&mut self, count: usize) -> Result
Reads at least count
bytes into an internal buffer, returning the available
count if successful, or an end-of-stream error if not. For a softer version
that returns whether enough bytes are available, use request
.
Sourcefn read_exact_bytes<'a>(&mut self, buf: &'a mut [u8]) -> Result<&'a [u8]>
fn read_exact_bytes<'a>(&mut self, buf: &'a mut [u8]) -> Result<&'a [u8]>
Reads the exact length of bytes into a slice, returning the bytes read if successful, or an end-of-stream error if not. Bytes are not consumed if an end-of-stream error is returned.
Sourcefn read_array<const N: usize>(&mut self) -> Result<[u8; N]>where
Self: Sized,
fn read_array<const N: usize>(&mut self) -> Result<[u8; N]>where
Self: Sized,
Reads an array with a size of N
bytes.
Sourcefn read_u16_le(&mut self) -> Result<u16>
fn read_u16_le(&mut self) -> Result<u16>
Reads a little-endian u16
.
Sourcefn read_i16_le(&mut self) -> Result<i16>
fn read_i16_le(&mut self) -> Result<i16>
Reads a little-endian i16
.
Sourcefn read_u32_le(&mut self) -> Result<u32>
fn read_u32_le(&mut self) -> Result<u32>
Reads a little-endian u32
.
Sourcefn read_i32_le(&mut self) -> Result<i32>
fn read_i32_le(&mut self) -> Result<i32>
Reads a little-endian i32
.
Sourcefn read_u64_le(&mut self) -> Result<u64>
fn read_u64_le(&mut self) -> Result<u64>
Reads a little-endian u64
.
Sourcefn read_i64_le(&mut self) -> Result<i64>
fn read_i64_le(&mut self) -> Result<i64>
Reads a little-endian i64
.
Sourcefn read_u128_le(&mut self) -> Result<u128>
fn read_u128_le(&mut self) -> Result<u128>
Reads a little-endian u128
.
Sourcefn read_i128_le(&mut self) -> Result<i128>
fn read_i128_le(&mut self) -> Result<i128>
Reads a little-endian i128
.
Sourcefn read_usize(&mut self) -> Result<usize>
fn read_usize(&mut self) -> Result<usize>
Sourcefn read_isize(&mut self) -> Result<isize>
fn read_isize(&mut self) -> Result<isize>
Sourcefn read_usize_le(&mut self) -> Result<usize>
fn read_usize_le(&mut self) -> Result<usize>
Sourcefn read_isize_le(&mut self) -> Result<isize>
fn read_isize_le(&mut self) -> Result<isize>
Sourcefn read_int<T: PrimInt + Pod>(&mut self) -> Result<T>where
Self: Sized,
fn read_int<T: PrimInt + Pod>(&mut self) -> Result<T>where
Self: Sized,
Reads a big-endian integer.
Sourcefn read_int_le<T: PrimInt + Pod>(&mut self) -> Result<T>where
Self: Sized,
fn read_int_le<T: PrimInt + Pod>(&mut self) -> Result<T>where
Self: Sized,
Reads a little-endian integer.
Sourcefn read_data<T: Pod>(&mut self) -> Result<T>where
Self: Sized,
fn read_data<T: Pod>(&mut self) -> Result<T>where
Self: Sized,
Reads a value of generic type T
supporting an arbitrary bit pattern. See
Pod
.
Sourcefn read_utf8<'a>(
&mut self,
count: usize,
buf: &'a mut String,
) -> Result<&'a str>
fn read_utf8<'a>( &mut self, count: usize, buf: &'a mut String, ) -> Result<&'a str>
Reads up to count
bytes of UTF-8 into buf
, returning the string read.
If invalid bytes are encountered, an error is returned and buf
is unchanged.
In this case, the stream is left in a state with up to count
bytes consumed
from it, including the invalid bytes and any subsequent bytes.