tosc-rs / mgnp

MnemOS Global Networking Protocol
Creative Commons Attribution Share Alike 4.0 International
14 stars 1 forks source link

feat(tricky-pipe): consistent `oneshot::Receiver` API #22

Closed hawkw closed 8 months ago

hawkw commented 8 months ago

Currently, the tricky_pipe::oneshot API allows Senders to be constructed from either an Arc<Receiver<T>> or a &'static Receiver<T>. This means that in order to use a Receiver, it must be either inside an Arc or in a &'static. This isn't great, as it's difficult for other crates, like MGNP, to write APIs that take a Receiver<T> as an argument without caring whether it's in an Arc or a static.

This branch changes the oneshot API so that a Receiver<T> is agnostic over the storage type and holds a *const Oneshot<T> plus a type-erased drop function, like the way Senders currently work. A Receiver<T> can now be constructed from either an Arc<Oneshot<T>> or a &'static Oneshot<T>>. Now, we can write APIs in MGNP that accept a Receiver<T>, without caring which storage type is used; this allows the user to pass in whatever oneshot storage they like.