Crate pitwall_tauri

Crate pitwall_tauri 

Source
Expand description

§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

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

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

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

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-exports§

pub use bridge::to_channel;

Modules§

bridge
Stream-to-Channel Bridge

Structs§

Pitwall
Unified entry point for Pitwall telemetry connections.
SessionInfo
Session information extracted and parsed from iRacing’s YAML session data This matches the actual structure that iRacing outputs
VariableInfo
Information about a specific telemetry variable.
VariableSchema
Schema describing the structure and metadata of telemetry variables.

Enums§

UpdateRate
Update rate for telemetry streams
VariableType
Supported telemetry data types. Maps to iRacing SDK’s irsdk_VarType enum.