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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
//! # Pitwall-Tauri
//!
//! Tauri integration layer for the Pitwall telemetry library.
//!
//! This crate provides minimal, stateless bridges between Pitwall's streaming API
//! and Tauri's IPC channels, plus TypeScript type generation for compile-time
//! type safety between Rust and TypeScript.
//!
//! ## Features
//!
//! - **Stream Mirroring**: Simple `to_channel()` function for any Pitwall stream
//! - **Type Generation**: Export TypeScript bindings from Rust types
//! - **Zero State**: Completely stateless - user manages connection lifecycle
//! - **High Performance**: <1% CPU overhead for 60Hz telemetry streaming
//!
//! ## Quick Start
//!
//! ### 1. Define Your Frame Type
//!
//! ```rust,ignore
//! use pitwall::PitwallFrame;
//! use serde::{Serialize, Deserialize};
//! use specta::Type;
//!
//! #[derive(Debug, Clone, Serialize, Deserialize, Type, PitwallFrame)]
//! struct MyTelemetry {
//! #[pitwall(name = "Speed")]
//! speed: f32,
//!
//! #[pitwall(name = "Gear")]
//! gear: i32,
//!
//! #[pitwall(name = "RPM")]
//! rpm: f32,
//! }
//! ```
//!
//! ### 2. Create Tauri Command
//!
//! ```rust,ignore
//! use tauri::ipc::Channel;
//! use pitwall_tauri::to_channel;
//!
//! #[tauri::command]
//! async fn start_telemetry(
//! telemetry: Channel<MyTelemetry>,
//! session: Channel<SessionInfo>,
//! ) -> Result<(), String> {
//! let conn = Pitwall::connect().await
//! .map_err(|e| e.to_string())?;
//!
//! // Spawn telemetry stream
//! tokio::spawn({
//! let stream = conn.subscribe::<MyTelemetry>(UpdateRate::Native);
//! async move {
//! to_channel(stream, telemetry).await
//! }
//! });
//!
//! // Spawn session updates stream
//! tokio::spawn({
//! let stream = conn.session_updates();
//! async move {
//! to_channel(stream, session).await
//! }
//! });
//!
//! Ok(())
//! }
//! ```
//!
//! ### 3. Generate TypeScript Bindings
//!
//! ```rust,ignore
//! fn main() {
//! // Generate TypeScript types (run once during build or manually)
//! #[cfg(debug_assertions)]
//! {
//! tauri_specta::ts::export(
//! specta::collect_types![start_telemetry],
//! "../src/bindings.ts"
//! ).expect("Failed to export TypeScript bindings");
//! }
//!
//! tauri::Builder::default()
//! .invoke_handler(tauri::generate_handler![start_telemetry])
//! .run(tauri::generate_context!())
//! .expect("error while running tauri application");
//! }
//! ```
//!
//! ### 4. Use in TypeScript
//!
//! ```typescript
//! import { invoke, Channel } from '@tauri-apps/api/core';
//! import type { MyTelemetry, SessionInfo } from './bindings';
//!
//! const telemetryChannel = new Channel<MyTelemetry>();
//! const sessionChannel = new Channel<SessionInfo>();
//!
//! telemetryChannel.onmessage = (data) => {
//! console.log(`Speed: ${data.speed}, Gear: ${data.gear}`);
//! };
//!
//! sessionChannel.onmessage = (session) => {
//! console.log(`Track: ${session.weekend_info.track_name}`);
//! };
//!
//! await invoke('start_telemetry', {
//! telemetry: telemetryChannel,
//! session: sessionChannel,
//! });
//! ```
// Re-export Pitwall types for convenience
pub use ;
// Re-export bridge function as primary API
pub use to_channel;