Skip to main content

ModelCache

Struct ModelCache 

Source
pub struct ModelCache { /* private fields */ }
Expand description

A folder of downloaded model files, one <id>-<sha256>.gguf per row, so a row with another digest never reuses a file. A file is used only when its size and SHA-256 match, hashed once per process; fetch checks the SHA-256 before a file gets its final name. No call downloads alone.

Implementations§

Source§

impl ModelCache

Source

pub fn new(dir: impl Into<PathBuf>) -> Self

Uses dir as the model folder; it is created on the first fetch. Mobile apps pass their own app folder here. Output: the cache.

Source

pub fn default_dir() -> Result<Self, LocalError>

Picks the default folder: $TROUPEKIT_MODEL_DIR, else $HOME/.cache/troupekit/models, else %LOCALAPPDATA%\troupekit\models. Output: the cache, or Cache asking for ModelCache::new(dir).

Source

pub fn dir(&self) -> &Path

Returns the model folder. Input: none. Output: the folder path.

Source

pub fn path(&self, spec: &LocalSpec) -> Option<PathBuf>

Returns the file of a row when it is a regular file of exactly the declared size whose SHA-256 matches the row. The first call in a process hashes the file; later calls skip it while the file keeps its identity (device, inode, size, mtime). A partial or other file gives None. Never touches the network.

Source

pub async fn fetch( &self, spec: &LocalSpec, transport: &dyn Transport, ) -> Result<PathBuf, LocalError>

Downloads a row through transport unless path already finds it, following up to 5 redirects that stay on https: into a part file of its own (created exclusively, 0600), refused past the declared size or on a hash mismatch, then renamed. Output: the path.

Trait Implementations§

Source§

impl Clone for ModelCache

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for ModelCache

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Eq for ModelCache

Source§

impl PartialEq for ModelCache

Source§

fn eq(&self, other: &Self) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl StructuralPartialEq for ModelCache

Auto Trait Implementations§

§

impl Forget for ModelCache

§

impl Freeze for ModelCache
where *const u8 is !null: Freeze, PhantomData<u8>: Freeze,

§

impl Move for ModelCache

§

impl RefUnwindSafe for ModelCache

§

impl Send for ModelCache
where RawVecInner: Send,

§

impl Sync for ModelCache
where RawVecInner: Sync,

§

impl Unpin for ModelCache
where *const u8 is !null: Unpin,

§

impl UnsafeUnpin for ModelCache

§

impl UnwindSafe for ModelCache
where RawVecInner: UnwindSafe,

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> DynClone for T
where T: Clone,

Source§

fn __clone_box(&self, _: Private) -> *mut ()

Source§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn equivalent(&self, key: &K) -> bool

Compare self to key and return true if they are equal.
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.