1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
//! Stream-to-Channel Bridge
//!
//! Provides a simple, stateless bridge between Pitwall's async stream API
//! and Tauri's IPC channel system for high-frequency telemetry streaming.
use Stream;
use StreamExt;
/// Bridge a Pitwall stream to a Tauri IPC channel.
///
/// This function provides a stateless, zero-overhead bridge between Pitwall's
/// tokio-based async streams and Tauri's IPC channel system. It's designed for
/// high-frequency telemetry streaming (60Hz+) with minimal latency.
///
/// # Arguments
///
/// * `stream` - Any Pitwall stream (telemetry frames, session updates, etc.)
/// * `channel` - Tauri IPC channel for sending data to the frontend
///
/// # Returns
///
/// Returns `Ok(())` when the stream ends naturally, or an error if the channel
/// fails to send data.
///
/// # Example
///
/// ```rust,ignore
/// use pitwall::Pitwall;
/// use pitwall_tauri::to_channel;
/// use tauri::ipc::Channel;
///
/// #[tauri::command]
/// async fn start_telemetry(telemetry_channel: Channel<MyFrame>) {
/// let connection = Pitwall::connect().await?;
/// let stream = connection.subscribe::<MyFrame>(UpdateRate::Native);
///
/// // Spawn the bridge task
/// tokio::spawn(async move {
/// to_channel(stream, telemetry_channel).await
/// });
/// }
/// ```
///
/// # Performance
///
/// This bridge adds negligible overhead (~microseconds per frame) by:
/// - Using async/await for efficient task scheduling
/// - Avoiding unnecessary allocations
/// - Leveraging Tauri's optimized IPC serialization
///
pub async