Skip to main content

WebAssetLoader

Struct WebAssetLoader 

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

In-memory asset loader for the web target.

All loaded bytes live in a Mutex<HashMap> so the loader can satisfy the AssetLoader: Send + Sync bound. Lookups are cheap (single hash + clone of the byte vector). The cache is unbounded — preloaded assets stay resident for the lifetime of the loader.

Implementations§

Source§

impl WebAssetLoader

Source

pub fn new() -> Self

Create an empty loader. Use preload to fill it before any synchronous load() call.

Source

pub fn insert_raw(&self, key: impl Into<String>, bytes: Vec<u8>)

Insert raw bytes for key directly into the cache. Useful when the app already has asset bytes in hand (e.g. via include_bytes! for tiny bundled fonts) and doesn’t need a fetch() round-trip.

Source

pub fn len(&self) -> usize

Number of entries currently in the cache.

Source

pub fn is_empty(&self) -> bool

Whether the cache is empty.

Source

pub async fn preload(&self, _urls: &[&str]) -> Result<()>

Cross-host placeholder for preload. See the wasm32 variant for the real implementation.

Source

pub async fn fetch_bytes(_url: &str) -> Result<Vec<u8>>

Cross-host placeholder for fetch_bytes. Returns PlatformError::Unsupported because there is no fetch() API outside a browser. The non-wasm32 path exists so downstream cargo check from a desktop box doesn’t error on the missing item.

Trait Implementations§

Source§

impl AssetLoader for WebAssetLoader

Source§

fn load(&self, path: &AssetPath) -> Result<Vec<u8>>

Load an asset as raw bytes Read more
Source§

fn exists(&self, path: &AssetPath) -> bool

Check if an asset exists
Source§

fn platform_name(&self) -> &'static str

Get the platform name for this loader
Source§

fn load_string(&self, path: &AssetPath) -> Result<String, PlatformError>

Load an asset as a UTF-8 string
Source§

impl Debug for WebAssetLoader

Source§

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

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

impl Default for WebAssetLoader

Source§

fn default() -> WebAssetLoader

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

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

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.