-
-
Couldn't load subscription status.
- Fork 1.7k
Description
Compared to Bytes, Chunk is pointless and kinda frustrating:
- It's a trivial wrapper around
BytesbutBytesis exposed via theFrom/Intoimpl anyways so it's not like it's keeping it out of the public API Chunkadds 0 new functionality overBytes, all of its methods forwards toBytesanyway- There's no way to split a
Chunkwithout round-tripping throughBytes - Any third-party crate that wants to build on
Stream<Item = Bytes>needs special adapters to work withhyper::Body
That last one is a real problem for me because I'm finally updating multipart-async and trying to maximize interop by generifying the API as much as possible. Because hyper::Body doesn't implement AsyncRead I've instead standardized around a Stream<Item = impl BodyChunk> API where BodyChunk covers two operations: splitting and dereffing to &[u8]. My final constraint is that I want to be able to return the same impl BodyChunk type, mostly to make it easy to drop multipart-async into existing request handlers.
Without implementing BodyChunk specifically for hyper::Chunk while still having an applicable impl for it, I would need an impl that's generic over T: From<Bytes>, Bytes: From<T>, T: AsRef<[u8]>. My hangup on this is that I now cannot implement BodyChunk for &[u8] directly, which complicates testing as I have to convert all bytestring literals to Bytes. (I also want to avoid a generic impl based on Into<Bytes> as that operation may perform implicit copies and I'm trying to be near-zero-copy.)
I realize Chunk exists because it used to be a custom implementation of Bytes but at this point it can be changed to just be a type alias and basically nothing will break (except usages of Chunk::into_bytes(), ironically).