You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Right now this crate uses FromStr, but with #45 it might be better to use a custom trait, which has better support for parsing (the data will be consumed) and it would allow creating custom spans (without having to worry about indexing strings).
pubtraitParse<'a>{typeError;fnparse(input:Cursor<'a>) -> Result<Self,Self::Error>;/// Returns how many chars will be consumed when parsing, if this is known.fnconsumes() -> Option<usize>{None}}structCursor<'a>{buffer:&'astr,position:usize,}implCursor<'a>{pubfntake(&mutself,n:usize) -> Result<&str,Error>{self.position += n;self.peek(n)}pubfnpeek(&self,n:usize) -> Result<&str,Error>{self.buffer.get(self.position..self.position+n).ok_or_else(|| Error::unexpected_eof(n))}pubfntag<T:AsRef<str>>(&self,expected:T) -> Result<(),Error>{let tag = buffer.take()?;if expected.as_ref() == tag {Ok(())}else{Err(Error::mismatched_tag(expected.as_ref(), tag))}}}
The nice thing is that with the above approach one could make the Cursor generic over different kind of inputs (not limited to &str):
use std::marker::PhantomData;structCursor<'a,T = &'astr>{buffer:T,position:usize,_p:PhantomData<&'aT>,}
The text was updated successfully, but these errors were encountered:
Right now this crate uses
FromStr
, but with #45 it might be better to use a custom trait, which has better support for parsing (the data will be consumed) and it would allow creating custom spans (without having to worry about indexing strings).I think of something like this (inspired by
syn
):The nice thing is that with the above approach one could make the
Cursor
generic over different kind of inputs (not limited to&str
):The text was updated successfully, but these errors were encountered: