Replies: 2 comments 3 replies
-
|
More thoughts on why having However, when following the reasoning from above, On the other hand, the API still exposes a lot of types that might not be easy to use, e.g., |
Beta Was this translation helpful? Give feedback.
-
100% agree. I used IResult just for a quick example (prof of concept for myself). |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
Due to @FelixPodint's suggestion, I wanted to write down some thoughts on how to improve imap-codec's API.
I do like the idea of having
Encode(already implemented), andDecode(to be done).How should the
Decodetrait look like?@FelixPodint's suggested something like ...
... that can be implemented like this ...
... and be used like this ...
Questions:
The above solution would expose nom's
IResultto the public API. This can make sense, but I am not sure if it does here. Are there any features ofIResultthat we need?I think a better solution would be to use an
Outcome, (orParseResult,Result, ... -- name up to debate), e.g., like this ...These are the four cases I am aware of an IMAP server will experience when reading from network. For a more detailled explanation, see the command parsing example.
Decode?Encodeis pretty much implemented by any type in imap-codec, because it is used similar to howDisplayis used. An implementation ofEncodewill likely only serialize some required syntax here and there, but mostly arrange how to call furtherEncodefunctions.However, should we really implement
Decodefor all parsers, too? This would be another layer requiring maintenance. What would be the benefit?I would propose to implement
Decodeonly for the "happy path", that is, for all parsers directly required to produce a stream of IMAP commands or responses, i.e.,Greeting,Command,Response, and a small count of other types.For everything that is not directly relevant to processing a stream of IMAP objects, we would reference to the
internalmodule. Sadely, @FelixPodint, this would mean thatDecodewould not be implemented forEnvelopeand you would still need to refer to theinternalmodule.Other solutions
Response::from_bytesthat returns aParseResult.ParseResultexposes nom's internals.Decodertrait A real-world implementation should likely use this trait. In fact, imap-codec should provide aDecoderimplementation in the future (feature-gated withtokio-codecor so.).Beta Was this translation helpful? Give feedback.
All reactions