Skip to content
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

Writing code generic over client type? #18

Open
netvl opened this issue Dec 23, 2019 · 2 comments
Open

Writing code generic over client type? #18

netvl opened this issue Dec 23, 2019 · 2 comments

Comments

@netvl
Copy link
Contributor

netvl commented Dec 23, 2019

Currently Client is parametrized over the Read + Write + fmt::Debug types. Unfortunately, because this is a requirement of three non-marker traits, it does not seem possible to write code which is agnostic to the specific kind of the underlying stream by using a trait object like Box<dyn Read + Write + fmt::Debug>.

My use case is that I need to write some code which works with IMAP servers, but depending on configuration those servers can be TLS or non-TLS. As of now, it does not seem possible to handle such servers in a uniform way.

I'm frankly not sure how, but it would be great if the library supported some kind of a way to write code which does not depend on the connection details of a particular client and would allow working with any of them. I guess the most straightforward way to do it would be to extract the public interface of the Client and Session structs to traits, but given that traits can't have async method now, it might be hard to do...

@dignifiedquire
Copy link
Member

I agree this is an issue, I have not found a great solution that I like yet, but I definitely experienced this, which is why this file (https://github.com/deltachat/deltachat-core-rust/blob/master/src/imap_client.rs) exists.

but given that traits can't have async method now, it might be hard to do...

async-trait works quite well, so that might be possible.

@dignifiedquire
Copy link
Member

we could take some inspiriation from here https://docs.rs/async-tungstenite/0.3.1/async_tungstenite/stream/enum.Stream.html (haven't looked in detail yet)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants