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.
-
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
Decode
trait 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
IResult
to the public API. This can make sense, but I am not sure if it does here. Are there any features ofIResult
that 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
?Encode
is pretty much implemented by any type in imap-codec, because it is used similar to howDisplay
is used. An implementation ofEncode
will likely only serialize some required syntax here and there, but mostly arrange how to call furtherEncode
functions.However, should we really implement
Decode
for all parsers, too? This would be another layer requiring maintenance. What would be the benefit?I would propose to implement
Decode
only 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
internal
module. Sadely, @FelixPodint, this would mean thatDecode
would not be implemented forEnvelope
and you would still need to refer to theinternal
module.Other solutions
Response::from_bytes
that returns aParseResult
.ParseResult
exposes nom's internals.Decoder
trait A real-world implementation should likely use this trait. In fact, imap-codec should provide aDecoder
implementation in the future (feature-gated withtokio-codec
or so.).Beta Was this translation helpful? Give feedback.
All reactions