$ show RustAudio/coreaudio-rs
coreaudio-rs is a Rust library providing safe, zero-cost bindings to Apple's CoreAudio API, with particular focus on Audio Unit functionality. The library wraps the complex C API in Rust abstractions that maintain type safety and memory safety while preserving performance. It enables Rust developers to work with audio input/output, audio processing, and hardware interaction on Apple platforms (macOS, iOS, tvOS, visionOS). The architecture follows a modular library design with core functionality in src/, platform-specific helpers in src/audio_unit/macos_helpers.rs, and comprehensive examples demonstrating usage patterns. The library relies on the objc2 crate family for Objective-C interoperability and bitflags for flag management. Data flows involve audio buffers moving between hardware devices and AudioUnit instances through callback mechanisms, with configuration flowing from Rust definitions to the CoreAudio API. Entry points include the main library interface in src/lib.rs, the AudioUnit constructor and methods in src/audio_unit/mod.rs, and platform-specific initialization helpers. The examples directory provides practical demonstrations of audio playback, input/output streaming, and advanced audio unit configuration.
The LLM identified 2 files worth highlighting for reuse:
Provides a comprehensive error handling system that maps CoreAudio's OSStatus codes to meaningful Rust enum variants. Implements proper From traits for conversion, Display and Error traits for user-friendly error reporting, and a unified Error enum that aggregates all possible CoreAudio error domains. Demonstrates skilled FFI error handling by preserving original error codes while providing Rust-idiomatic error types.
Defines type-safe representations of CoreAudio audio formats and their associated flags using Rust enums and bitflags. Eliminates magic numbers by wrapping raw CoreAudio constants in meaningful, self-documenting types. Includes conversion functions between the Rust representations and the original C format/flag pairs. Demonstrates skilled API wrapping by maintaining type safety while preserving full compatibility with the underlying C API.