Comments (2)
Not a problem!
Consider Take which uses PhantomData
for the I : RangeStream
parameter since Rust requires that all type paramters of a type is actually used in the type itself.
pub struct Take<I>(usize, PhantomData<fn(I) -> I>);
impl<I> Parser for Take<I>
where I: RangeStream,
I::Range: ::primitives::Range
{
type Input = I;
type Output = I::Range;
fn parse_lazy(&mut self, mut input: Self::Input) -> ConsumedResult<Self::Output, Self::Input> {
...
}
}
So why can't we just have pub struct Take(usize);
?
Well, the Parser
implementation uses I
for its associated Input
type and all associated types must be fully specified from the Self
type (Take<I>
). If I
did not appear in Take
Rust rejects the impl
as you could have Take : Parser<Input = &str>
and Take : Parser<Input = &[u8]>
etc.
It is actually possible to be a bit more clever and move Input
to a trait parameter instead as below which will let use remove the I
parameter and I have actually tried doing that in the past. However it turns out that if Parser
is implemented as below rust can start failing to infer the correct type for Input
in not to uncommon cases and the only way to resolve that is to force users to add type annotations which is not particularly user friendly.
impl<I> Parser<I> for Take
where I: RangeStream,
I::Range: ::primitives::Range
{
type Output = I::Range;
fn parse_lazy(&mut self, mut input: I) -> ConsumedResult<Self::Output, I> {
...
}
}
Anyways, that is the gist of it. Do you have any reason other than curiosity towards this? I feel its more of an implementation detail so I am not sure it belongs in the README since it is really just an implementation detail. (Not that implementation details are worth documenting. I guess as long as it is not front and center it can belong there).
from combine.
@Marwes wow, great answer. Thanks for being so responsive!
Do you have any reason other than curiosity towards this?
Not really. I wrote a small combinator and really had to dig into the source to understand some subtleties (confounded by this being my "learn Rust!" project), so I wanted to really understand what was going on in the guts.
I feel its more of an implementation detail so I am not sure it belongs in the README since it is really just an implementation detail. (Not that implementation details are worth documenting. I guess as long as it is not front and center it can belong there).
I'm fine with this. I prefer to phrase tickets/issues as "complete this action" or "solve this problem", so I phrased my question as "document this curiousity" rather than "answer my question". But you've answered my question and we can link to this discussion rather than fold it into the README as you see fit.
from combine.
Related Issues (20)
- Is there a way to get `Stream<Token=char>` from `io::Read`? HOT 1
- Tools for debugging recursion problems? HOT 4
- Some issue with error reporting
- Errors include unprintable or awkwardly printed characters. HOT 6
- `expected` error strings always quote what was expected, even if it isn't a literal HOT 3
- How about offset into some data? HOT 3
- Outdated tutorial HOT 1
- Native/abstracted sub-parsers HOT 6
- XML parsing for React.js to Solid.js conversion HOT 4
- Comparison with LALRPOP
- Unbounded mutual recursion in Parser impl HOT 3
- Adivce on reducing code size in WASM target HOT 7
- Docs unclear whether `parser!` should be used on nightly rust HOT 2
- Parse `std::process::Child` stdout
- Successful parser will not clear the error stack HOT 1
- build failure
- Implement Pratt parsing or precedence climbing HOT 4
- Choice with Vec of parsers HOT 4
- Documentation request: no_partial
- Worse performance after parsing 2 large values HOT 9
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from combine.