From 1545ed40e73d19bd079980ccef19d92d04a1658c Mon Sep 17 00:00:00 2001 From: Andrew Golovashevich Date: Mon, 10 Nov 2025 11:56:47 +0300 Subject: [PATCH] Redesigned SourceStream to be more safe --- Cargo.toml | 2 +- src/lib.rs | 25 +++++++++++++++++++------ 2 files changed, 20 insertions(+), 7 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 5b9e848..b12f669 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,5 +1,5 @@ [package] -name = "source_stream_0" +name = "source-stream-0" edition = "2024" [lib] \ No newline at end of file diff --git a/src/lib.rs b/src/lib.rs index 11e18c1..5af594f 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -24,10 +24,23 @@ pub trait CollectedSubstring { fn compareKeyword(&self, kw: impl _Keyword); } -pub trait SourceStream> { - fn skip(&mut self, predicate: impl Predicate); - fn collect(&mut self, predicate: impl Predicate) -> CS; +pub enum CollectResult { + EOF, + NotMatches, + Matches(T) +} - fn pos(&mut self) -> P; - fn currentChar(&mut self) -> C; -} \ No newline at end of file +pub trait SourceStream> { + /** + * Returns `true` if the end of stream reached. + */ + fn skip(&mut self, predicate: impl Predicate) -> bool; + fn collect(&mut self, predicate: impl Predicate) -> CollectResult; + + fn pos(&self) -> P; + + fn currentChar(&self) -> Option; + fn nextChar(&mut self) -> Option; + + fn isEnded(&self) -> bool; +}