Skip to main content

Asset

Trait Asset 

Source
pub trait Asset<B>:
    'static
    + Send
    + Sync
    + Sized {
    type Source: 'static + Send + Sync;
    type Deps<'a>: Dependencies<'a>;

    // Required method
    fn upload<'a>(
        source: &Self::Source,
        backend: &B,
        deps: &Self::Deps<'a>,
    ) -> Option<Self>;
}
Expand description

Describes how a source asset of type Self::Source is converted into a processed asset Self, optionally using a backend B.

B is intentionally generic — it is not restricted to GPU backends:

  • CPU → GPU: B is your graphics backend (e.g. a wgpu Device).
  • CPU → CPU: set B = () for pure data transforms (e.g. decoding, decompression, or format conversion with no device required).
  • Audio / other: set B to your audio device or any other service.

§Associated types

  • Source — the raw unprocessed data stored in Assets<Source>.
  • Deps — zero or more additional resources required during the conversion (see Dependencies). Use () when there are no extra dependencies.

§Upload lifecycle

AssetPlugin drains the dirty queue from Assets<Source> each tick and calls [upload] for every pending entry. Returning None re-queues the handle for the next tick, allowing conversions to wait on sub-resources that may not be ready yet.

Required Associated Types§

Source

type Source: 'static + Send + Sync

The raw source representation stored in Assets.

Source

type Deps<'a>: Dependencies<'a>

Resources (beyond B itself) required to perform the conversion. Use () when there are no extra dependencies.

Required Methods§

Source

fn upload<'a>( source: &Self::Source, backend: &B, deps: &Self::Deps<'a>, ) -> Option<Self>

Convert source into a processed asset using backend and deps.

Return None to defer the conversion to the next tick (e.g. a required sub-resource is not yet available).

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§