Discussion: how to implement Source
for lazy readers, like T: Read
or T: BufRead
#324
Labels
Source
for lazy readers, like T: Read
or T: BufRead
#324
Hello all,
I'd like to open this discussion because, to me, it would be fascinating that Logos supports
Source
types others thanstr
and[u8]
, especially lazy readers like those who implementRead
orBufRead
.impl<T: Read> Source <T>
, orimpl<T: Read + Seek> Source <T>
would be a game changer to me, as it would allow to lex some string without needing to allocate it completely.I have tried a bit of different implementation, but I already see some shortcomings that need to be addressed or discussed:
Source::len() -> usize
should maybe beSource::len_hint() -> Option<usize>
Source::read_*
methods should take mutable reference to the reader (but it maybe will reduce performances for types likestr
or[u8]
that do not need mutability).offset
position may not be good, especially since this may require usingSeek::seek
. If backtracking is never allowed, then using onlyread
methods should be fine, no?Read
is enough, because we may be loosing all reference to the original source. ImplementingSource for Bytes
may be a solution.My question is then: did anyone already think about this problem? Has anyone some ideas or suggestions?
The text was updated successfully, but these errors were encountered: