I'm writing a web server using Actix-web. I have a cache component that stores some data as Arc<[u8]>, now I'd like to send these directly without making an unnecessary copy.
I didn't find any direct way to do this, so I've tried to figure out how to implement the MessageBody trait for my wrapper type, but I'm getting stuck on converting Arc<[u8]> to actix_web::web::Bytes. The docs actually talk about Bytes supporting Arc, but I can't find any way to actually use that.
What is the best way to serve Arc<[u8]> body in Actix-web?
Considering that
Bytesis a reference-counted and copy-on-write container for a byte array, it's semantically very similar toArc<[u8]>but with some extra features. I would suggest changing your cache to storeBytesvalues instead ofArc<[u8]>and then the problem goes away.