[−][src]Trait fbxcel::pull_parser::reader::ParserSource
A trait for types which can be data sources.
Users can implement this manually, but usually it is enough to use wrappers
in the reader
module.
Required methods
fn position(&self) -> u64
Returns the offset of a byte which would be read next.
This is called many times during parsing, so it is desirable to be fast as possible.
Reader types with std::io::Seek
can implement this as
self.seek(SeekFrom::Current(0)).unwrap()
, but this is fallible and
can be inefficient.
Use of PositionCacheReader
is reccomended.
Provided methods
fn skip_distance(&mut self, distance: u64) -> Result<()>
Skips (seeks formward) the given size.
Reader types can make this more efficient using std::io::Seek::seek
if possible.
Examples
use fbxcel::pull_parser::{ParserSource, reader::PlainSource}; let msg = "Hello, world!"; let len = msg.len() as u64; let mut reader = std::io::Cursor::new(msg); let mut reader = PlainSource::new(&mut reader); assert_eq!(reader.position(), 0); reader.skip_distance(7).expect("Failed to skip"); assert_eq!(reader.position(), 7);
fn skip_to(&mut self, pos: u64) -> Result<()>
Skips (seeks forward) to the given position.
Reader types can make this more efficient using std::io::Seek::seek
if possible.
Panics
Panics if the given position is behind the current position.
use fbxcel::pull_parser::{ParserSource, reader::PlainSource}; let msg = "Hello, world!"; let len = msg.len() as u64; let mut reader = std::io::Cursor::new(msg); let mut reader = PlainSource::new(&mut reader); assert_eq!(reader.position(), 0); reader.skip_to(2).expect("Failed to skip"); assert_eq!(reader.position(), 2); reader.skip_to(7).expect("Failed to skip"); assert_eq!(reader.position(), 7);