Skip to main content

Assets

Struct Assets 

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

Every image one book refers to, probed once and indexed.

DrawItem::Image.asset indexes this: layout places an image by number, and painters resolve the number back to bytes.

Implementations§

Source§

impl Assets

Source

pub fn none() -> Assets

No images at all: what a host with no loader supplies.

Source

pub fn probe( book: &Book, styles: &StyleTree, loader: &dyn ImageLoader, ) -> Assets

Probes every image the book places and every image its sheet puts behind a box, the manuscript’s own first. A url the loader cannot resolve, or bytes no probe recognises, is a diagnostic and no asset.

A sheet that names no background image offers the loader nothing beyond what the manuscript named.

Source

pub fn add(&mut self, url: &str, bytes: Vec<u8>) -> Added

Registers one image the host handed over, and what that did: the same bytes it already had, new bytes at a fresh or existing index, or bytes no probe recognises.

This is the door for a host that pushes: a worker has no loader to reach back through, so images cross the wall the way font files do. A url pushed again with the bytes it already answers for costs nothing; pushed again with different bytes, it replaces them in place, keeping the index DrawItem::Image.asset already names.

Source

pub fn lookup(&self, url: &str) -> Option<(u32, Intrinsic)>

The asset registered for a url, and its index.

Source

pub fn probed(&self, url: &str) -> bool

Whether a url has been probed: an asset came of it, or a complaint about why none did. A url nobody offered is neither, and is what layout reports.

Source

pub fn assets(&self) -> &[Asset]

Every asset, in the order DrawItem::Image.asset indexes them.

Source

pub fn bytes(&self, index: u32) -> Option<&[u8]>

The file one asset was probed from: the bytes a painter embeds, unchanged from what the host handed over.

Source

pub fn digest(&self, index: u32) -> Option<u64>

What one asset’s file hashes to: what tells a trace of the bytes an index holds now from a trace of the bytes it held before.

Source

pub fn warnings(&self) -> &[Warning]

What probing had to complain about.

Trait Implementations§

Source§

impl Debug for Assets

Source§

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

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

impl Default for Assets

Source§

fn default() -> Assets

Returns the “default value” for a type. Read more
Source§

impl ImageLoader for Assets

The images a host already handed over answer by the url they were registered under, with the bytes as they arrived.

Source§

fn load(&self, url: &str) -> Option<Vec<u8>>

The bytes behind one url, or None when the host cannot resolve it.

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<T> ErasedDestructor for T
where T: 'static,

§

impl<T> Finish for T

§

fn finish(self)

Does nothing but move self, equivalent to drop.
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.

§

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 = Infallible

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

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

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.