The Rust Std Library is great, so my question is: Would Rust Peakable be ok to write an input buffer/ lookahead algorithm while precisely being able to write a lookahead algorithm for another language like SQL.
1)Does anyone have experience with Rust Peekable and are there any "do's and donts"?
I have suedo code for the look ahead algorithm. Would it be better to write a lookahead algorithm from scratch or use Rust Peekable?
Do you know of any online resources that demonstrate lookahead alogrithms in rust or other languages?
I'm not sure I understand what you are referring to, but maybe you are interested in peekable iterators from the standard library?
On (almost) any Rust iterator you can call the Iterator::peekable() method to get a new version of the iterator that supports seeing into the future (peeking) via the peek() and peek_mut() methods. The documentation for peekable() and peek() have some usage examples.
The implementation of the Peekable iterator is fairly straightforward: when you call peek(), it calls next() on the underlying iterator and internally stores the result before returning a reference to it. If you keep calling peek(), you will keep getting a reference to this cached result and the underlying iterator won't be advanced. When you finally call next(), the cached result is consumed and returned.
It is useful for when you want to have a look at the next value in an iterator to decide whether you are ready to deal with it or not, but you don't want to implement yourself the logic necessary to keep the value around in case you are not ready to use it.
There's buffer_redux's BufReader which can be used with a MinBuffered policy to essentially implement N bytes lookahead on a Read stream. I can't vouch for the crate's soundness, however, as it does use a lot of unsafe code internally.
My question was not well worded. That's my error. Im writing a SQL implementation for a database. Im busy with the lexical analysis phase. In that phase the scanner needs to read ahead a few characters to correctly match multiple characters in a string. That can be done with the regex crate but im trying to find a simpler more concise way to do that with a look ahead algorithm.