Redesigned SourceStream to be more safe

This commit is contained in:
Andrew Golovashevich 2025-11-10 11:56:47 +03:00
parent 730742639d
commit 1545ed40e7
2 changed files with 20 additions and 7 deletions

View File

@ -1,5 +1,5 @@
[package]
name = "source_stream_0"
name = "source-stream-0"
edition = "2024"
[lib]

View File

@ -24,10 +24,23 @@ pub trait CollectedSubstring<C> {
fn compareKeyword(&self, kw: impl _Keyword<C>);
}
pub trait SourceStream<C, P: Pos, CS: CollectedSubstring<C>> {
fn skip(&mut self, predicate: impl Predicate<C>);
fn collect(&mut self, predicate: impl Predicate<C>) -> CS;
fn pos(&mut self) -> P;
fn currentChar(&mut self) -> C;
pub enum CollectResult<T> {
EOF,
NotMatches,
Matches(T)
}
pub trait SourceStream<C, P: Pos, CS: CollectedSubstring<C>> {
/**
* Returns `true` if the end of stream reached.
*/
fn skip(&mut self, predicate: impl Predicate<C>) -> bool;
fn collect(&mut self, predicate: impl Predicate<C>) -> CollectResult<CS>;
fn pos(&self) -> P;
fn currentChar(&self) -> Option<C>;
fn nextChar(&mut self) -> Option<C>;
fn isEnded(&self) -> bool;
}