pub trait Source<'de, S: Str<'de>> {
// Required methods
fn offset(&self) -> usize;
fn limit(&self) -> usize;
fn read_u8_char(&mut self) -> IoResult<u8>;
fn read_str(&mut self, n: usize) -> IoResult<S>;
unsafe fn read_until(&mut self, byte: u8) -> IoResult<S>;
}
Expand description
Represents a data source for a Str
.
This is analogous to Read
,
except with arbitrary, potentially non-static return type S: Str
,
and provides methods optimized for usage in parsing.
Required Methods§
Sourcefn limit(&self) -> usize
fn limit(&self) -> usize
Returns the maximum possible number of bytes in the source.
This value is used for security reasons, to avoid out-of-memory error from arbitrarily large numbers as requested by the serialization.
Sourcefn read_u8_char(&mut self) -> IoResult<u8>
fn read_u8_char(&mut self) -> IoResult<u8>
Reads one byte from the source.
§Errors
If the byte is not an ASCII character,
this method returns Error::BadEncoding
.
If the source has already ended,
this method MUST return Error::UnexpectedEof
(instead of io::ErrorKind::UnexpectedEof
).
If an IO error occurs,
the error is returned directly wrapped in IoError::Io
.
Sourcefn read_str(&mut self, n: usize) -> IoResult<S>
fn read_str(&mut self, n: usize) -> IoResult<S>
Reads n
bytes from the source.
§Errors
If the nth byte does ont terminate a character boundary,
this method should return Error::BadEncoding
.
If the source has less remaining characters available than n
,
this method MUST return Error::UnexpectedEof
(instead of io::ErrorKind::UnexpectedEof
).
If an IO error occurs,
the error is returned directly wrapped in IoError::Io
.
Sourceunsafe fn read_until(&mut self, byte: u8) -> IoResult<S>
unsafe fn read_until(&mut self, byte: u8) -> IoResult<S>
Reads the source until the byte byte
.
This method consumes the slice before byte
AND byte
itself,
but only returns the slice before byte
.
§Safety
byte
must be a valid ASCII character.