[][src]Trait phpser::Source

pub trait Source<'de, S: Str<'de>> {
    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>; }

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

fn offset(&self) -> usize

Returns the number of bytes already read from the 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.

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.

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.

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.

Loading content...

Implementations on Foreign Types

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

Loading content...

Implementors

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

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

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

Loading content...