async-bincode
async-bincode copied to clipboard
Need Example
it's very hard to understand how to use this crate.
I'd be happy to accept a PR that adds an example! The basic idea is that you use AsyncBincodeX
to wrap a AsyncX
(e.g., AsyncBincodeReader
to wrap a type that implements AsyncRead
), and then you use that as a Stream
(for AsyncRead
) or Sink
(for AsyncWrite
). AsyncBincodeStream
wraps something that is AsyncRead + AsyncWrite
and gives you something that is Stream + Sink
.
How could I I don't understand your crate xd, how could I use bincode with stream ?
You need to have some type that implements AsyncRead
, say a socket
, and then you do AsyncBincodeReader::from(socket)
. The thing you get back you can then use as a Stream
.
One thing I found confusing was when I tried to use AsyncBincodeStream
was the lack of bounds on Deserialize/Serialize for T
. This is more discoverable when looking at AsyncBincodeWriter
and AsyncBincodeReader
, as the bounds are directly laid out there. The compiler just told me that my AsyncBincodeStream
did not implement Stream
, which was not helpful in figuring out the problem.
Perhaps adding more explicit bounds would be helpful to users (it certainly would've helped me). I'd be happy to provide a PR for that.
So, this is actually kind of on purpose, as there's a general recommendation in Rust to not have bounds on datastructures, and instead have them on methods/trait impls only as necessary. It avoids polluting lots of code with repeated bounds. If you can think of a nice improvement to the docs in this regard though, that'd be great!
I understand that point, but shouldn't it be sufficient to add the bounds to the From and Default impls? That doesn't pollute everything with bounds, but gives immediate feedback to what is required when you're constructing the types.
I'll be happy to provide a patch for your inspection, no worries if you then still don't like it :)
I'll reply in-PR :)