pub struct MediaStore { /* private fields */ }Expand description
Images kept as versioned artifacts, named by digest.
put_image decodes once under the decode limits, computes the
digest, and saves a Part::InlineData; identical bytes in one scope are one artifact.
load checks the digest of what it reads back.
§Example
use std::sync::Arc;
use adk_artifact::InMemoryArtifactService;
use adk_vision::{DecodedImage, MediaScope, MediaStore, Provenance};
let store = MediaStore::new(Arc::new(InMemoryArtifactService::new()));
let scope = MediaScope::new("desk", "u1", "s1");
let png = DecodedImage::filled(8, 8, [255, 0, 0, 255]).encode_png()?;
let (image, source) = store.put_image(&scope, png.clone(), Provenance::Upload).await?;
let (again, _) = store.put_image(&scope, png, Provenance::Upload).await?;
assert_eq!(again.artifact, image.artifact);
assert_eq!(store.load(&image).await?.digest(), source.digest());Implementations§
Source§impl MediaStore
impl MediaStore
Sourcepub fn new(artifacts: Arc<dyn ArtifactService>) -> Self
pub fn new(artifacts: Arc<dyn ArtifactService>) -> Self
A store over an artifact service, with the default decode limits.
Sourcepub fn with_limits(self, limits: DecodeLimits) -> Self
pub fn with_limits(self, limits: DecodeLimits) -> Self
Sets the decode limits.
Sourcepub fn limits(&self) -> &DecodeLimits
pub fn limits(&self) -> &DecodeLimits
The decode limits.
Sourcepub async fn put_image(
&self,
scope: &MediaScope,
bytes: Vec<u8>,
provenance: Provenance,
) -> Result<(ImageRef, SourceImage)>
pub async fn put_image( &self, scope: &MediaScope, bytes: Vec<u8>, provenance: Provenance, ) -> Result<(ImageRef, SourceImage)>
Decodes, checks and stores encoded image bytes.
§Errors
A decode refusal (DecodedImage::decode) before anything is stored, or the
artifact service’s error.
Sourcepub async fn put_pixels(
&self,
scope: &MediaScope,
pixels: DecodedImage,
provenance: Provenance,
) -> Result<(ImageRef, SourceImage)>
pub async fn put_pixels( &self, scope: &MediaScope, pixels: DecodedImage, provenance: Provenance, ) -> Result<(ImageRef, SourceImage)>
Sourcepub async fn load_bytes(&self, image: &ImageRef) -> Result<Vec<u8>>
pub async fn load_bytes(&self, image: &ImageRef) -> Result<Vec<u8>>
Loads an image’s encoded bytes, checking them against its digest.
§Errors
The artifact service’s error, VisionError::InvalidInput when the artifact is not
inline image data, or VisionError::DigestMismatch when the bytes changed.
Sourcepub async fn load(&self, image: &ImageRef) -> Result<SourceImage>
pub async fn load(&self, image: &ImageRef) -> Result<SourceImage>
Trait Implementations§
Source§impl Clone for MediaStore
impl Clone for MediaStore
Auto Trait Implementations§
impl !RefUnwindSafe for MediaStore
impl !UnwindSafe for MediaStore
impl Forget for MediaStore
impl Freeze for MediaStorewhere
*const ArcInner<dyn ArtifactService> is !null: Freeze,
PhantomData<ArcInner<dyn ArtifactService>>: Freeze,
impl Move for MediaStore
impl Send for MediaStore
impl Sync for MediaStore
impl Unpin for MediaStore
impl UnsafeUnpin for MediaStorewhere
*const ArcInner<dyn ArtifactService> is !null: UnsafeUnpin,
PhantomData<ArcInner<dyn ArtifactService>>: UnsafeUnpin,
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,
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.