capnproto-rust
capnproto-rust copied to clipboard
`!Send` impl for various reader types
Is there any reason why capnp::struct_list::Reader and similar types are not Send? That makes it quite hard to use them in a async context, where each value of those iterator is later used to spawn of a future task.
I just stumbled on this. I don't understand why some things would have to be !Send when the TypedReader is okay to send. It seems the *_capnp::foo::Reader just contains raw pointers and ended up being !Send by default. Those should be fine to mark as Send.
See also https://github.com/capnproto/capnproto-rust/issues/180#issuecomment-938226071
// this is a TypedReader<BufferSegments<&[u8]>, ...>
let typed_reader = ...;
// the TypedReader is fine to send across await
while let Some(blah) = my_stream.next().await {
// but the *_capnp::foo::Reader isn't
// and I have to do this on every iteration
let foo = typed_reader.get().unwrap();
...
}
Okay so https://github.com/capnproto/capnproto-rust/issues/479#issuecomment-1913742538 points out Readers are not safe to Send because they borrow the underlying buffer. Hmm.
In my use case, my data source is (moral equivalent of) Arc<Box<u8>>. It'd be nice to have a Send or Send+Sync Reader when the data source happens to be Send/Sync.