diwic / reffers-rs

Rust wrappers around references, boxes and Arcs.
68 stars 3 forks source link

Send version of ARef #2

Closed scottlamb closed 7 years ago

scottlamb commented 7 years ago

hyper's new async API allows me to send my HTTP response via a futures::Stream<Item = Chunk, Error = hyper::Error>, where Chunk can be anything that satisfies 'static + Send + AsRef<[u8]>. I'd like my Chunk type to be something like ARef<[u8]>.

This would let me (among other things) use mmaped memory without extra copies, trim the beginning and end of a Vec<u8> before passing it along, etc. More motivation here. I talked about owning_ref there, but I think ARef is even better because I don't have to wrap it in an enum.

The problem is that ARef<[u8]> isn't Send. Maybe there should be a parallel type that is?

diwic commented 7 years ago

Yes, this makes a lot of sense to me. Implemented now. Enjoy!