Redesigned SourceStream to be more safe
This commit is contained in:
parent
730742639d
commit
1545ed40e7
@ -1,5 +1,5 @@
|
||||
[package]
|
||||
name = "source_stream_0"
|
||||
name = "source-stream-0"
|
||||
edition = "2024"
|
||||
|
||||
[lib]
|
||||
25
src/lib.rs
25
src/lib.rs
@ -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;
|
||||
pub enum CollectResult<T> {
|
||||
EOF,
|
||||
NotMatches,
|
||||
Matches(T)
|
||||
}
|
||||
|
||||
fn pos(&mut self) -> P;
|
||||
fn currentChar(&mut self) -> C;
|
||||
}
|
||||
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;
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user