pub struct VerifiedModel { /* private fields */ }Expand description
A model whose every file matched its manifest, under a licence the gate allowed.
Implementations§
Source§impl VerifiedModel
impl VerifiedModel
Sourcepub fn check_dir(
manifest: &ModelManifest,
dir: &Path,
gate: &LicenceGate<'_>,
) -> Result<Self>
pub fn check_dir( manifest: &ModelManifest, dir: &Path, gate: &LicenceGate<'_>, ) -> Result<Self>
Checks the files of manifest in dir, laid out at their manifest paths, after the
licence gate allows the model. Every file is hashed on every call, so a file changed
since an earlier check is caught.
§Errors
The licence gate’s refusal, then the first file’s VerifiedFile::check error.
§Example
use adk_vision::{
Digest, InMemoryAcceptanceStore, LicenceGate, LicencePolicy, ModelManifest,
VerifiedModel, VisionError,
};
let dir = tempfile::tempdir().unwrap();
std::fs::write(dir.path().join("w.bin"), b"weights").unwrap();
let manifest = ModelManifest::from_json(&format!(r#"{{
"id": "toy", "task": "detect",
"source": {{"kind": "local", "dir": "{}"}},
"files": [{{"path": "w.bin", "size": 7, "sha256": "{}"}}],
"licence": {{"id": "MIT", "url": "https://opensource.org/license/mit", "class": "permissive"}},
"runtime": {{"kind": "candle"}}
}}"#, dir.path().display(), Digest::of(b"weights"))).unwrap();
let (policy, store) = (LicencePolicy::new(), InMemoryAcceptanceStore::new());
let gate = LicenceGate::new(&policy, &store);
assert!(VerifiedModel::check_dir(&manifest, dir.path(), &gate).is_ok());
std::fs::write(dir.path().join("w.bin"), b"tamper!").unwrap();
let err = VerifiedModel::check_dir(&manifest, dir.path(), &gate).unwrap_err();
assert!(matches!(err, VisionError::DigestMismatch { .. }));Sourcepub fn manifest(&self) -> &ModelManifest
pub fn manifest(&self) -> &ModelManifest
The manifest.
Sourcepub fn files(&self) -> impl Iterator<Item = &VerifiedFile>
pub fn files(&self) -> impl Iterator<Item = &VerifiedFile>
The verified files, in manifest order.
Sourcepub fn file(&self, path: &str) -> Option<&VerifiedFile>
pub fn file(&self, path: &str) -> Option<&VerifiedFile>
The verified file at a manifest path.
Trait Implementations§
Source§impl Clone for VerifiedModel
impl Clone for VerifiedModel
Source§impl Debug for VerifiedModel
impl Debug for VerifiedModel
Source§impl PartialEq for VerifiedModel
impl PartialEq for VerifiedModel
impl StructuralPartialEq for VerifiedModel
Auto Trait Implementations§
impl Forget for VerifiedModel
impl Freeze for VerifiedModelwhere
*const u8 is !null: Freeze,
PhantomData<u8>: Freeze,
PhantomData<ModelFile>: Freeze,
PhantomData<String>: Freeze,
PhantomData<(String, VerifiedFile)>: Freeze,
impl Move for VerifiedModel
impl RefUnwindSafe for VerifiedModel
impl Send for VerifiedModelwhere
RawVecInner: Send,
impl Sync for VerifiedModelwhere
RawVecInner: Sync,
impl Unpin for VerifiedModel
impl UnsafeUnpin for VerifiedModelwhere
*const u8 is !null: UnsafeUnpin,
PhantomData<u8>: UnsafeUnpin,
PhantomData<ModelFile>: UnsafeUnpin,
PhantomData<String>: UnsafeUnpin,
PhantomData<(String, VerifiedFile)>: UnsafeUnpin,
impl UnwindSafe for VerifiedModelwhere
RawVecInner: UnwindSafe,
Blanket Implementations§
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,
Source§impl<T> Downcast for T
impl<T> Downcast for T
impl<T> ErasedDestructor for Twhere
T: 'static,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
Source§fn in_current_span(self) -> Instrumented<Self> ⓘ
fn in_current_span(self) -> 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 moreSource§impl<F, T> IntoSample<T> for Fwhere
T: FromSample<F>,
impl<F, T> IntoSample<T> for Fwhere
T: FromSample<F>,
fn into_sample(self) -> T
impl<T> MaybeSend for Twhere
T: Send,
Source§impl<T> Pointable for T
impl<T> Pointable for T
Source§impl<T> PolicyExt for Twhere
T: ?Sized,
impl<T> PolicyExt for Twhere
T: ?Sized,
impl<T> Read<Exclusive, BecauseExclusive> for Twhere
T: ?Sized,
impl<T> Scalar for T
impl<T> Scalar for T
Source§impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
Source§fn to_subset(&self) -> Option<SS>
fn to_subset(&self) -> Option<SS>
The inverse inclusion map: attempts to construct
self from the equivalent element of its
superset. Read moreSource§fn is_in_subset(&self) -> bool
fn is_in_subset(&self) -> bool
Checks if
self is actually part of its subset T (and can be converted to it).Source§fn to_subset_unchecked(&self) -> SS
fn to_subset_unchecked(&self) -> SS
Use with care! Same as
self.to_subset but without any property checks. Always succeeds.Source§fn from_subset(element: &SS) -> SP
fn from_subset(element: &SS) -> SP
The inclusion map: converts
self to the equivalent element of its superset.Source§impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
Source§fn to_subset(&self) -> Option<SS>
fn to_subset(&self) -> Option<SS>
The inverse inclusion map: attempts to construct
self from the equivalent element of its
superset. Read moreSource§fn is_in_subset(&self) -> bool
fn is_in_subset(&self) -> bool
Checks if
self is actually part of its subset T (and can be converted to it).Source§fn to_subset_unchecked(&self) -> SS
fn to_subset_unchecked(&self) -> SS
Use with care! Same as
self.to_subset but without any property checks. Always succeeds.Source§fn from_subset(element: &SS) -> SP
fn from_subset(element: &SS) -> SP
The inclusion map: converts
self to the equivalent element of its superset.