Skip to content

sync: implement Sink and Stream for Signal#5491

Open
wojciech-graj wants to merge 1 commit intoembassy-rs:mainfrom
wojciech-graj:stream-sink-signal
Open

sync: implement Sink and Stream for Signal#5491
wojciech-graj wants to merge 1 commit intoembassy-rs:mainfrom
wojciech-graj:stream-sink-signal

Conversation

@wojciech-graj
Copy link
Contributor

@wojciech-graj wojciech-graj commented Feb 18, 2026

The traits are implemented on a reference to Signal, because Signal
is used for both sending and receiving, requires an immutable
reference for both operations, and the Stream and Sink traits take a
mutable reference.

@wojciech-graj wojciech-graj marked this pull request as draft February 18, 2026 17:21
@wojciech-graj wojciech-graj marked this pull request as ready for review February 18, 2026 17:25
The traits are implemented on a reference to Signal, because Signal
is used for both sending and receiving, requires an immutable
reference for both operations, and the Stream and Sink traits take a
mutable reference.
@Dirbaio
Copy link
Member

Dirbaio commented Feb 18, 2026

the impls feel a bit weird, since signal has space for only 1 element and loses the old value if it hasn't been picked up you typically don't use it to send streams of data like you would with a channel. What's the use case?

@wojciech-graj
Copy link
Contributor Author

My use-case is implementing some networking code in which I only care about the latest packet, and want to use a standard Sink/Stream interface. But this would be useful for any code that uses Sink/Stream, but doesn't care about losing data.

For prior art, see tokio's WatchStream (tokio doesn't have a Sink impl, as they dropped all of them a while ago)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants