fm_bindings/
lib.rs

1//! # Foundation Models Bindings for Rust
2//!
3//! Rust bindings for Apple's [Foundation Models framework](https://developer.apple.com/documentation/foundationmodels),
4//! providing access to on-device large language models (LLMs) that power Apple Intelligence.
5//!
6//! ## Requirements
7//!
8//! - macOS 26+ or iOS 26+
9//! - Apple Intelligence enabled in System Settings
10//!
11//! ## Features
12//!
13//! - **Blocking Response**: Get complete responses with `response()`
14//! - **Streaming Response**: Get real-time incremental updates with `stream_response()`
15//! - Type-safe error handling with `Result<T, Error>`
16//! - Zero-copy FFI layer for optimal performance
17//!
18//! ## Examples
19//!
20//! ### Blocking Response
21//!
22//! ```no_run
23//! use fm_bindings::LanguageModelSession;
24//!
25//! fn main() -> Result<(), Box<dyn std::error::Error>> {
26//!     let session = LanguageModelSession::new()?;
27//!     let response = session.response("What is Rust?")?;
28//!     println!("{}", response);
29//!     Ok(())
30//! }
31//! ```
32//!
33//! ### Streaming Response
34//!
35//! ```no_run
36//! use fm_bindings::LanguageModelSession;
37//! use std::io::{self, Write};
38//!
39//! fn main() -> Result<(), Box<dyn std::error::Error>> {
40//!     let session = LanguageModelSession::new()?;
41//!
42//!     session.stream_response("Tell me a story", |chunk| {
43//!         print!("{}", chunk);
44//!         let _ = io::stdout().flush();
45//!     })?;
46//!
47//!     println!(); // newline after stream
48//!     Ok(())
49//! }
50//! ```
51
52// Internal modules
53mod error;
54mod ffi;
55mod session;
56
57// Public API exports
58pub use error::{Error, Result};
59pub use session::LanguageModelSession;