acc_shared_memory_rs/lib.rs
1//! # ACC Shared Memory (Rust)
2//!
3//! A Rust library for reading Assetto Corsa Competizione (ACC) shared memory telemetry data.
4//! This is a port of the Python acc_shared_memory library.
5//!
6//! ## Features
7//!
8//! - Read real-time telemetry data from ACC
9//! - Type-safe enums for all ACC status codes
10//! - Structured data types for physics, graphics, and static information
11//! - Cross-platform shared memory access (Windows)
12//!
13//! ## Usage
14//!
15//! ```no_run
16//! use acc_shared_memory_rs::{ACCSharedMemory, ACCError};
17//!
18//! fn main() -> Result<(), ACCError> {
19//! let mut acc = ACCSharedMemory::new()?;
20//!
21//! loop {
22//! if let Some(data) = acc.read_shared_memory()? {
23//! println!("Speed: {:.1} km/h, RPM: {}",
24//! data.physics.speed_kmh,
25//! data.physics.rpm);
26//! }
27//! std::thread::sleep(std::time::Duration::from_millis(16));
28//! }
29//! }
30//! ```
31
32pub mod core;
33pub mod datatypes;
34pub mod enums;
35pub mod maps;
36pub mod parsers;
37
38pub use core::ACCSharedMemory;
39pub use maps::ACCMap;
40
41/// Error types for ACC shared memory operations
42#[derive(thiserror::Error, Debug)]
43pub enum ACCError {
44 #[error("Shared memory not available or game not running")]
45 SharedMemoryNotAvailable,
46
47 #[error("Failed to open shared memory: {0}")]
48 SharedMemoryOpen(String),
49
50 #[error("Failed to map shared memory: {0}")]
51 SharedMemoryMap(String),
52
53 #[error("Timeout waiting for fresh data")]
54 Timeout,
55
56 #[error("Invalid data format: {0}")]
57 InvalidData(String),
58
59 #[error("Windows API error: {0}")]
60 WindowsApi(String),
61}
62
63pub type Result<T> = std::result::Result<T, ACCError>;