From fcb530425af3b4bdc248955523f31437b1d4eab3 Mon Sep 17 00:00:00 2001 From: Andrew Golovashevich Date: Tue, 18 Nov 2025 15:43:42 +0300 Subject: [PATCH] Renamed 'wrapper' -> 'converter' --- ascii/Cargo.toml | 4 +-- {wrapper => converter}/Cargo.toml | 2 +- {wrapper => converter}/src/lib.rs | 55 +++++++++++++++++-------------- 3 files changed, 32 insertions(+), 29 deletions(-) rename {wrapper => converter}/Cargo.toml (69%) rename {wrapper => converter}/src/lib.rs (71%) diff --git a/ascii/Cargo.toml b/ascii/Cargo.toml index b8cccaf..73d5d23 100644 --- a/ascii/Cargo.toml +++ b/ascii/Cargo.toml @@ -4,6 +4,4 @@ edition = "2024" [lib] -[dependencies] -source-stream-0 = { path = ".." } -source-stream-0-wrapper-0 = { path = "../wrapper" } +[dependencies] \ No newline at end of file diff --git a/wrapper/Cargo.toml b/converter/Cargo.toml similarity index 69% rename from wrapper/Cargo.toml rename to converter/Cargo.toml index 2e04524..3bb2fe5 100644 --- a/wrapper/Cargo.toml +++ b/converter/Cargo.toml @@ -1,5 +1,5 @@ [package] -name = "source-stream-0-wrapper-0" +name = "source-stream-0-converter-0" edition = "2024" [lib] diff --git a/wrapper/src/lib.rs b/converter/src/lib.rs similarity index 71% rename from wrapper/src/lib.rs rename to converter/src/lib.rs index f0c969d..1f3bf1f 100644 --- a/wrapper/src/lib.rs +++ b/converter/src/lib.rs @@ -9,19 +9,19 @@ use std::marker::PhantomData; pub trait SourceStreamConverter_Char { type WC; - fn wrapChar(c: C) -> Self::WC; + fn convertChar(&self, c: C) -> Self::WC; } pub trait StreamConverter_Pos<'pos, P: Pos<'pos>> { type WP: Pos<'pos>; - fn wrapPos(p: P) -> Self::WP; + fn convertPos(&self, p: P) -> Self::WP; } pub trait StreamConverter_Substring<'source, C, CS: CollectedSubstring<'source, C = C>>: SourceStreamConverter_Char { type WCS: CollectedSubstring<'source, C = Self::WC>; - fn wrapSubstring(wcs: CS) -> Self::WCS; + fn convertSubstring(&self, wcs: CS) -> Self::WCS; } pub trait StreamConverter<'source, 'pos, C, P: Pos<'pos>, CS: CollectedSubstring<'source, C = C>>: @@ -31,7 +31,7 @@ pub trait StreamConverter<'source, 'pos, C, P: Pos<'pos>, CS: CollectedSubstring { } -struct PredicateWrapper< +struct PredicateConverter< 'predicate, 'converter, C, @@ -44,10 +44,10 @@ struct PredicateWrapper< } impl<'predicate, 'converter, C, W: SourceStreamConverter_Char, I: Predicate> - PredicateWrapper<'predicate, 'converter, C, W, I> + PredicateConverter<'predicate, 'converter, C, W, I> { fn wrap(pred: &'predicate mut I, converter: &'converter W) -> Self { - return PredicateWrapper { + return PredicateConverter { _orig: pred, _converter: converter, __phantom: PhantomData::default(), @@ -56,14 +56,14 @@ impl<'predicate, 'converter, C, W: SourceStreamConverter_Char, I: Predicate, I: Predicate> Predicate - for PredicateWrapper<'predicate, 'converter, C, W, I> + for PredicateConverter<'predicate, 'converter, C, W, I> { fn check(&mut self, chr: C) -> bool { - return self._orig.check(W::wrapChar(chr)); + return self._orig.check(self._converter.convertChar(chr)); } } -pub struct SourceStreamWrapper< +pub struct ConvertedSourceStream< 'source, 'pos, C, @@ -85,7 +85,7 @@ impl< CS: CollectedSubstring<'source, C = C>, W: StreamConverter<'source, 'pos, C, P, CS>, I: SourceStream<'source, 'pos, C = C, P = P, CS = CS>, -> SourceStream<'source, 'pos> for SourceStreamWrapper<'source, 'pos, C, P, CS, W, I> +> SourceStream<'source, 'pos> for ConvertedSourceStream<'source, 'pos, C, P, CS, W, I> { type C = W::WC; type P = W::WP; @@ -93,34 +93,39 @@ impl< fn skip(&mut self, predicate: &mut impl Predicate) -> bool { self._src - .skip(&mut PredicateWrapper::wrap(predicate, &self._converter)) + .skip(&mut PredicateConverter::wrap(predicate, &self._converter)) } fn collect(&mut self, predicate: &mut impl Predicate) -> CollectResult { match self ._src - .collect(&mut PredicateWrapper::wrap(predicate, &self._converter)) + .collect(&mut PredicateConverter::wrap(predicate, &self._converter)) { CollectResult::EOF => return CollectResult::EOF, CollectResult::NotMatches => return CollectResult::NotMatches, - CollectResult::Matches(cs) => return CollectResult::Matches(W::wrapSubstring(cs)), + CollectResult::Matches(cs) => { + return CollectResult::Matches(self._converter.convertSubstring(cs)); + } } } fn pos(&self) -> W::WP { - return W::wrapPos(self._src.pos()); + return self._converter.convertPos(self._src.pos()); } fn currentChar(&self) -> Option { - return self._src.currentChar().map(W::wrapChar); + return self + ._src + .currentChar() + .map(|c| self._converter.convertChar(c)); } fn nextChar(&mut self) -> Option { - return self._src.nextChar().map(W::wrapChar); + return self._src.nextChar().map(|c| self._converter.convertChar(c)); } } -pub struct KeywordUnwrapper< +pub struct KeywordDeconverted< 'keyword, 'converter, C, @@ -133,10 +138,10 @@ pub struct KeywordUnwrapper< } impl<'keyword, 'converter, C, W: SourceStreamConverter_Char, I: Keyword> - KeywordUnwrapper<'keyword, 'converter, C, W, I> + KeywordDeconverted<'keyword, 'converter, C, W, I> { fn unwrap(kw: &'keyword I, converter: &'converter W) -> Self { - return KeywordUnwrapper { + return KeywordDeconverted { _orig: kw, _converter: converter, __phantom: PhantomData::default(), @@ -145,7 +150,7 @@ impl<'keyword, 'converter, C, W: SourceStreamConverter_Char, I: Keyword, I: Keyword> Keyword - for KeywordUnwrapper<'keyword, 'converter, C, W, I> + for KeywordDeconverted<'keyword, 'converter, C, W, I> { fn startComparation<'self_>( &'self_ self, @@ -154,7 +159,7 @@ impl<'keyword, 'converter, C, W: SourceStreamConverter_Char, I: Keyword, I: Keyword { _orig: I, _converter: &'converter W, - __phantom: PhantomData<(&'keyword(), C)>, + __phantom: PhantomData<(&'keyword (), C)>, } impl< @@ -181,9 +186,9 @@ impl< W: SourceStreamConverter_Char, I: KeywordComparatorIterator<'keyword, W::WC>, > KeywordComparatorIterator<'keyword, C> - for KeywordComparatorWrapper<'keyword, 'converter, C, W, I> + for KeywordComparatorConverter<'keyword, 'converter, C, W, I> { fn consume(&mut self, c: C) -> bool { - todo!() + self._orig.consume(self._converter.convertChar(c)) } }