tflite-c-rs 0.0.1

Safe Rust wrapper for the TensorFlow Lite C API via runtime dynamic loading (libloading) — no build-time TFLite link required.
Documentation
//! # tflite-c-rs
//!
//! A small, safe Rust wrapper around the TensorFlow Lite C API that resolves
//! the shared library at *runtime* with [`libloading`] instead of linking
//! against it at build time. The crate ships no native code, no `build.rs`,
//! no `-sys` crate — it dynamically opens a TFLite shared object that you
//! (or your platform package manager) provide separately, then offers a
//! tidy, RAII-driven API on top of the resolved C symbols.
//!
//! ## Why runtime dynamic loading?
//!
//! The TensorFlow Lite C library is famously awkward to link statically:
//! its build system is Bazel-only, the released prebuilt binaries are
//! platform-specific, and cross-compilation against it tends to drag the
//! entire TensorFlow source tree along for the ride. For many real-world
//! deployments — embedded Linux, edge accelerators, vendor-shipped
//! NPU stacks — the path of least resistance is to ship the vendor's
//! prebuilt `.so`/`.dylib`/`.dll` and pick it up at runtime.
//!
//! That is exactly what this crate does. It uses `libloading` to `dlopen`
//! the TFLite C library, caches the symbols it needs, and exposes a small
//! safe surface (`Model`, `InterpreterOptions`, `Interpreter`, `Tensor`,
//! `ExternalDelegate`) on top of it.
//!
//! ## Quick start
//!
//! ```no_run
//! use tflite_c::{TfLiteLibrary, Model, InterpreterOptions, Interpreter};
//!
//! # fn run() -> Result<(), tflite_c::Error> {
//! let lib = TfLiteLibrary::load_default()?;
//! let model = Model::from_file("model.tflite", lib.clone())?;
//!
//! let mut options = InterpreterOptions::new(lib.clone());
//! options.num_threads(2);
//!
//! let mut interp = Interpreter::new(model, options)?;
//!
//! // Fill input 0 with whatever bytes your model expects.
//! interp.input_mut(0)?.data_mut()?.fill(0);
//!
//! interp.invoke()?;
//!
//! let out = interp.output(0)?;
//! let probs = out.to_vec_f32()?;
//! println!("first prob: {}", probs[0]);
//! # Ok(()) }
//! ```
//!
//! ## Threading
//!
//! [`Interpreter`] is `Send + Sync`, but TensorFlow Lite's C interpreter is
//! *not* thread-safe in itself. The standard pattern is to share via
//! `Arc<Mutex<Interpreter>>` (or `Arc<parking_lot::Mutex<Interpreter>>`) and
//! serialize every call into a given interpreter.
//!
//! ## Relationship to the upstream C API
//!
//! Type and function names that begin with `TfLite…` come from the upstream
//! header [`c_api.h`](https://github.com/tensorflow/tensorflow/blob/master/tensorflow/lite/c/c_api.h)
//! and the external-delegate header
//! [`c_api_experimental.h`](https://github.com/tensorflow/tensorflow/blob/master/tensorflow/lite/c/c_api_experimental.h).
//! This crate covers the minimum set required to load a model, run
//! inference, and read results — enough for v0.0.1.

#![deny(missing_docs)]
#![deny(unused_imports)]
#![cfg_attr(docsrs, feature(doc_cfg))]

pub mod error;
pub mod ffi;
pub mod interpreter;
pub mod library;
pub mod model;
pub mod tensor;

pub use crate::error::{Error, Result};
pub use crate::ffi::{TfLiteQuantizationParams, TfLiteStatus, TfLiteType};
pub use crate::interpreter::{Interpreter, InterpreterOptions};
pub use crate::library::{ExternalDelegate, ExternalDelegateBuilder, TfLiteLibrary};
pub use crate::model::Model;
pub use crate::tensor::{Tensor, TensorMut};