pub struct ModelFolder { /* private fields */ }Expand description
A folder that holds models, each in a folder of its own.
use std::sync::atomic::AtomicBool;
use ravenrs_ai::{LocalModel, ModelFamily, ModelFile, ModelFolder};
const MODEL: LocalModel = LocalModel {
id: "tiny",
name: "Tiny",
license: "MIT",
family: ModelFamily::Qwen3,
memory: 2_000_000_000,
understood: None,
files: &[ModelFile {
name: "tiny.gguf",
url: "https://example.invalid/tiny.gguf",
bytes: 1024,
sha256: "0000000000000000000000000000000000000000000000000000000000000000",
}],
};
let folder = ModelFolder::new("models");
folder.download(&MODEL, &|received, total| println!("{received} of {total}"), &AtomicBool::new(false))?;
folder.remove(&MODEL)?;Implementations§
Source§impl ModelFolder
impl ModelFolder
Sourcepub fn new(root: impl Into<PathBuf>) -> Self
pub fn new(root: impl Into<PathBuf>) -> Self
A folder at root. It is created when something is downloaded.
Sourcepub fn path_of(&self, model: &LocalModel, file: &ModelFile) -> PathBuf
pub fn path_of(&self, model: &LocalModel, file: &ModelFile) -> PathBuf
Where a file of model is, or would be.
Sourcepub fn state(&self, model: &LocalModel) -> ModelState
pub fn state(&self, model: &LocalModel) -> ModelState
Where model stands. Quick: it compares sizes, as the hash was checked when
it arrived.
Sourcepub fn download(
&self,
model: &LocalModel,
progress: &dyn Fn(u64, u64),
cancelled: &AtomicBool,
) -> Result<(), ModelError>
pub fn download( &self, model: &LocalModel, progress: &dyn Fn(u64, u64), cancelled: &AtomicBool, ) -> Result<(), ModelError>
Downloads what is missing of model and installs each file only if its hash
is right. It blocks until the end, so call it away from the UI thread.
progress gets the bytes received and the total, and cancelled is looked
at between chunks.
§Errors
Why it did not arrive. Files already checked stay, so trying again goes on from there, and the one being downloaded is erased.
Sourcepub fn remove(&self, model: &LocalModel) -> Result<(), ModelError>
pub fn remove(&self, model: &LocalModel) -> Result<(), ModelError>
Removes everything of model, including a download left halfway.
§Errors
When the disk refuses. A model that is not there is not an error.
Trait Implementations§
Source§impl Clone for ModelFolder
impl Clone for ModelFolder
Source§fn clone(&self) -> ModelFolder
fn clone(&self) -> ModelFolder
Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreSource§impl Debug for ModelFolder
impl Debug for ModelFolder
impl Eq for ModelFolder
Source§impl PartialEq for ModelFolder
impl PartialEq for ModelFolder
impl StructuralPartialEq for ModelFolder
Auto Trait Implementations§
impl Freeze for ModelFolder
impl RefUnwindSafe for ModelFolder
impl Send for ModelFolder
impl Sync for ModelFolder
impl Unpin for ModelFolder
impl UnsafeUnpin for ModelFolder
impl UnwindSafe for ModelFolder
Blanket Implementations§
impl<T> AutoreleaseSafe for Twhere
T: ?Sized,
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
Checks if this value is equivalent to the given key. Read more
§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
Compare self to
key and return true if they are equal.impl<T> ErasedDestructor for Twhere
T: 'static,
§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
Converts
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
Converts
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more