Skip to main content

Previews

Struct Previews 

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

Cached, isolated conversions (one per server, part of AppState).

Implementations§

Source§

impl Previews

Source

pub fn new(vault: &Vault, limits: PreviewLimits) -> Previews

Source

pub async fn render<T, F>(&self, key: &str, work: F) -> AppResult<T>
where T: Send + 'static, F: FnOnce() -> T + Send + 'static,

Runs CPU-bound work on a derived cache entry – drawing a thumbnail, composing an assembly preview – off the async runtime: at most MAX_RENDERS at a time and one at a time per key (the path of the entry). work must look in the cache before it does anything, so requests that waited for the same key answer from what the first one stored instead of doing it again. A request that only reads the cache does not come here and never waits for a slot.

The slot and the turn stay taken until work returns, also when the request that started it is gone: a blocking thread cannot be stopped, and its work is still running.

Source

pub fn dir(&self) -> &Path

The cache directory (<vault>/previews), also of the thumbnails.

Source

pub fn queue(&self) -> (usize, usize)

The preview queue: conversions running now and conversions waiting for a free slot (at most MAX_PARALLEL run at a time).

Source

pub fn assembly_path(&self, sha256: &str, key: &str) -> AppResult<PathBuf>

Where the composed preview of an assembly is cached: next to the blob’s own preview, named by the components it was built from (key, hex), so a changed component gives a new file.

Source

pub async fn mass_geometry( &self, vault: &Vault, sha256: &str, format: PreviewFormat, ) -> AppResult<Geometry>

The mass properties of a blob per unit density in model units (see massprops): from the cache, or computed from the cached preview mesh in the isolated preview process (converting the file first if needed). Failures are cached like failed previews.

Source

pub async fn has_mesh(&self, sha256: &str) -> bool

Whether the preview mesh of a blob is already cached.

Source

pub async fn is_converted(&self, sha256: &str) -> bool

Whether the conversion of a blob is behind us: its preview mesh or the reason why there is none is cached.

Source

pub async fn signature( &self, vault: &Vault, sha256: &str, format: PreviewFormat, ) -> AppResult<Signature>

The shape signature of a blob (see shape): from the cache, written by the conversion, or computed from the cached preview mesh in the isolated preview process. Failures are cached like failed previews.

Source

pub async fn mesh( &self, vault: &Vault, sha256: &str, format: PreviewFormat, ) -> AppResult<PathBuf>

The cached mesh of a blob, converting it first if necessary.

Source

pub fn warm( self: &Arc<Self>, vault: &Vault, sha256: &str, format: PreviewFormat, )

Starts the conversion in the background (after an upload), so the first viewer does not have to wait.

Auto Trait Implementations§

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
§

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

§

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

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

§

impl<A, B, T> HttpServerConnExec<A, B> for T
where B: Body,

§

impl<T> Instrument for T

§

fn instrument(self, span: Span) -> Instrumented<Self> ⓘ

Instruments this type with the provided [Span], returning an Instrumented wrapper. Read more
§

fn in_current_span(self) -> Instrumented<Self> ⓘ

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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> IntoEither for T

Source§

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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
where F: FnOnce(&Self) -> bool,

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
§

impl<T> Parallelizable for T
where T: Send + Sync,

§

impl<T> Pointable for T

§

const ALIGN: usize

The alignment of pointer.
§

type Init = T

The type for initializers.
§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
§

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

§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns [Action::Follow] only if self and other return Action::Follow. Read more
§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns [Action::Follow] if either self or other returns Action::Follow. Read more
§

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

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
§

impl<U, T> ToOwnedObj<U> for T
where U: FromObjRef<T>,

§

fn to_owned_obj(&self, data: FontData<'_>) -> U

Convert this type into T, using the provided data to resolve any offsets.
§

impl<U, T> ToOwnedTable<U> for T
where U: FromTableRef<T>,

§

fn to_owned_table(&self) -> U

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.
§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

§

fn vzip(self) -> V

§

impl<T> WithSubscriber for T

§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> ⓘ
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a [WithDispatch] wrapper. Read more
§

fn with_current_subscriber(self) -> WithDispatch<Self> ⓘ

Attaches the current default Subscriber to this type, returning a [WithDispatch] wrapper. Read more