Skip to main content

ModelLoader

Trait ModelLoader 

Source
pub trait ModelLoader {
    // Required methods
    fn format_name(&self) -> &'static str;
    fn probe(&self, bytes: &[u8]) -> bool;
    fn load(&self, path: &Path) -> Result<LoadedModel>;
}
Expand description

A parser for one on-disk model format.

Implemented by crate::GgufLoader and crate::SafeTensorsLoader. The trait exists (rather than two unrelated load free functions) so that callers who do know their format up front can hold a Box<dyn ModelLoader> chosen once, and so that load_model itself is just “try each known loader” instead of hand-rolled dispatch logic duplicated at every call site that needs to support both formats.

Required Methods§

Source

fn format_name(&self) -> &'static str

A short, lowercase name for the format this loader parses — always one of the format strings this loader’s errors carry.

Source

fn probe(&self, bytes: &[u8]) -> bool

Cheap, non-destructive sniff: does bytes (the start of the file) look like this loader’s format? Used by load_model to pick a loader by content rather than by file extension.

A true result is not a promise the file will load successfully — only that it is worth trying. A false result is a promise this loader will refuse the file, so load_model can skip straight to the next candidate without wasting a full parse attempt.

Source

fn load(&self, path: &Path) -> Result<LoadedModel>

Parses the file at path into a LoadedModel.

Dyn Compatibility§

This trait is dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§