Crate baton

Source
Expand description

Baton is a simple channel that only keeps the latest value. If you try to Send too quickly, then oops the Recv side will drop the baton.

Comes with a useful Baton macro to create a Send and Recv half for an entire struct. This allows you to send and receive updates independently for each field so it’s clear what changed.

The API is inspired by tokio::sync::watch but with a simpler design given the 1:1 nature. Notably, [Recv::recv] will return a reference to the next value so you don’t have to fumble around with changed() state. Additionally, there’s no way to accidentally deadlock like with tokio::sync::watch::Ref.

Structs§

Recv
The receiving half. Returns or waits for each update, potentially skipping them if too slow.
Send
The sending half. Sends new values to the receiving half, potentially dropping them if too fast.

Functions§

channel
Create a new channel with a Send and Recv half. This is a simple channel with no back-pressure and an initial value.

Derive Macros§

Baton
Derive a struct, creatig a XxxSet and XxxGet struct. Each field has its own channel, allowing you to send and receive updates independently.