-
-
Notifications
You must be signed in to change notification settings - Fork 4
Refactor imap_flow::stream
#37
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
6c9af26 to
879c0f4
Compare
Pull Request Test Coverage Report for Build 6539697912
💛 - Coveralls |
|
I'm not sure if this is really the best solution. We should discuss this. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks!
Recapping to test my understanding:
The main improvement is that instead of pub trait Stream, we now have trait AsyncReadWrite (which doesn't need to be exposed.) This is possible by introducing the read, read_mut, ... methods that don't expose a trait pairing AsyncRead + AsyncWrite but gives separate handles AsyncRead, AsyncWrite.
Technically, we could also "inline" the AsyncReadWrite trait and impl all methods directly on Stream?
Are there any downsides to this solution despite it having more code?
Bonus:
- Better names
AnyStream -> Stream✅ - Better access
.0 -> write_mut(see question) ✅
From my understanding, this PR is definitely an improvement. As we are still in an experimenting phase, I would propose to merge it after resolving the rename suggesstion. Then, I will rebase my work on the examples + tui and we can see how it goes.
| fn read(self: Pin<&Self>) -> Pin<&(dyn AsyncRead + Send)>; | ||
| fn read_mut(self: Pin<&mut Self>) -> Pin<&mut (dyn AsyncRead + Send)>; | ||
| fn write(self: Pin<&Self>) -> Pin<&(dyn AsyncWrite + Send)>; | ||
| fn write_mut(self: Pin<&mut Self>) -> Pin<&mut (dyn AsyncWrite + Send)>; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Question: Should we rename these to reader, reader_mut, writer, writer_mut, instead?
This is not possible because dyn can only be combined with a single (normal) trait (yet). Similarly dyn downcasting is not (yet) possible, so we need these methods on the trait. Another option would be to implement |
Ah, sorry. I now see why it's not possible. We could also get rid of It's a bit... unwieldy, see PS: Urgs, STARTTLS may require dyn :-/ Or IMAP's |
This type parameter is parasitic and will effect many types. It will result in very, VERY ugly type annotations... e.g. Proxy<ConnectedState<TcpStream, TlsStream<TcpStream>>>But hey, that's how Rust works, it's worth a try.
Can you elaborate this more? |
Are you sure about |
No. It was just a draft to see how bad it would be :-)
When STARTTLS is used, we need to replace When COMPRESS is used, we need to replace Combined... we need to handle (and make room for) ...
... in our client. |
|
Interesting... I'm not sure how we should proceed. Maybe we should keep dyn trait. Maybe we should avoid both dyn trait and the type parameter and instead be more strict so we can prevent cases like |
|
Okay! I feel that an enum with four states could be a bit annoying. But it would definitely be the tightest model of a sane IMAP reality. Feel free to close this PR. Looking forward to revisit! |
|
This gets out-of-sync. Shall we close for now? Maybe there are fragments we could still merge? |
|
I would like to keep this PR for irrational reasons. |
|
Release it. It wants to be free! |
Previously there were two public types in
imap_flow::stream:Stream: This trait existed only for technical reasons. The user might think that they should implement it, which is wrong.AnyStream. Handles the boxing, the pinning and the dynamic dispatch. This is the type that the user should interact with.The new API looks like this:
imap_flow::streamhas now only a single type, the structStream_::newAsyncReadvia_::readand_::read_mutAsyncWritevia_:::writeand_::write_mutClientFlowandServerFlowprovide access to the underlyingStreamvia_::streamand_::stream_mutCloses #18