Buttplug sex toy control library
1// Buttplug Rust Source Code File - See https://buttplug.io for more info.
2//
3// Copyright 2016-2024 Nonpolynomial Labs LLC. All rights reserved.
4//
5// Licensed under the BSD 3-Clause license. See LICENSE file in the project root
6// for full license information.
7
8use async_stream::stream;
9use futures::{Stream, pin_mut};
10use tokio::sync::broadcast;
11
12pub fn convert_broadcast_receiver_to_stream<T>(
13 receiver: broadcast::Receiver<T>,
14) -> impl Stream<Item = T>
15where
16 T: Unpin + Clone,
17{
18 stream! {
19 pin_mut!(receiver);
20 while let Ok(val) = receiver.recv().await {
21 yield val;
22 }
23 }
24}