pub fn load_from_bytes<M: DeserializeOwned>(
data: &[u8],
expected_type: ModelType,
) -> Result<M>Expand description
Load a model from a byte slice (spec 1.1 - Single Binary Deployment)
Enables the include_bytes!() pattern for embedding models directly
in executables. This is the key function for zero-dependency ML deployment.
§Arguments
data- Raw .apr file bytes (e.g., frominclude_bytes!())expected_type- Expected model type (for type safety)
§Example
ⓘ
use aprender::format::{load_from_bytes, ModelType};
// Embed model at compile time
const MODEL: &[u8] = include_bytes!("sentiment.apr");
fn main() -> Result<()> {
let model: LogisticRegression = load_from_bytes(MODEL, ModelType::LogisticRegression)?;
let prediction = model.predict(&input)?;
Ok(())
}§Errors
Returns error on format error, type mismatch, or checksum failure