Trait Source

Source
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§

Source

fn offset(&self) -> usize

Returns the number of bytes already read from the source.

Source

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.

Source

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.

Source

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.

Source

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.

Implementations on Foreign Types§

Source§

impl<'t, 'de, S, T> Source<'de, S> for &'t mut T
where S: Str<'de>, T: Source<'de, S>,

Source§

fn offset(&self) -> usize

Source§

fn limit(&self) -> usize

Source§

fn read_u8_char(&mut self) -> IoResult<u8>

Source§

fn read_str(&mut self, n: usize) -> IoResult<S>

Source§

unsafe fn read_until(&mut self, byte: u8) -> IoResult<S>

Implementors§

Source§

impl<'de, R: Read> Source<'de, String> for StringReader<R>

Source§

impl<'de, R: Read> Source<'de, Vec<u8>> for ByteReader<R>

Source§

impl<'de, S: Str<'de>> Source<'de, S> for Cursor<S>