rust-lang / flate2-rs

DEFLATE, gzip, and zlib bindings for Rust
https://docs.rs/flate2
Apache License 2.0
891 stars 158 forks source link

Using the flate2 crate with only AsyncRead/AsyncWrite #268

Closed TheNeikos closed 2 years ago

TheNeikos commented 3 years ago

Hello! I'm trying to use a tcp OwnedWriteHalf from tokio with flate2, but am unable to do so as it does not implement Write and instead only implements AsyncWrite.

Is there a way for me to still use this library? Since GzEncoder etc... all require Write but also implement AsyncWrite when the wrapped T does, it feels like that the Write bound is too restrictive.

Simple playground: https://play.rust-lang.org/?version=stable&mode=debug&edition=2018&gist=b0c9dd53d0735d38f24e076a1469c9e0

gkelly commented 3 years ago

I think this comes from using the older AsyncRead/AsyncWrite definitions from tokio-io. In that crate they were extensions of Read/Write. But in more recent tokio they are not.

As @TheNeikos points out, this comes from the R: Read bound when using most of the ::new fns. This was always true in the past because of AsyncRead being historically Read.

TheNeikos commented 3 years ago

Ah, indeed in 2.0 it seems that the Write bound has been removed. Well, once it is updated to that, I can integrate this crate then 👍

gkelly commented 3 years ago

It looks like the plan might be to drop tokio support from this crate and have people depend on the async_compression crate for that instead: https://github.com/rust-lang/flate2-rs/pull/214