Skip to main content

Asset

Trait Asset 

Source
pub trait Asset: 'static {
    type Source: Clone + Hash + Send;
    type Output: Clone + Send;

    // Required method
    fn load(
        source: Self::Source,
        cx: &mut App,
    ) -> impl Future<Output = Self::Output> + Send + 'static;
}
Expand description

A value that GPUI loads in the background and shares between callers, such as an image.

Implement it on a type that holds no data, such as an empty enum. Then call crate::Window::use_asset or crate::Window::get_asset to load it. The first call for a source starts the load and returns None. Later calls share that load and return its output once it is ready. App::remove_asset discards the app-level entry so the next fetch starts a new load.

Required Associated Types§

Source

type Source: Clone + Hash + Send

The key that identifies the asset. Equal keys share one cache entry.

Source

type Output: Clone + Send

The result of loading. Callers receive clones of the cached output, so keep it cheap to clone.

Required Methods§

Source

fn load( source: Self::Source, cx: &mut App, ) -> impl Future<Output = Self::Output> + Send + 'static

Starts loading source, and returns the future that produces the output.

The cache calls this on the foreground thread, where cx is available. Read any app state needed to construct the request here; the returned future runs on the background executor.

Dyn Compatibility§

This trait is not dyn compatible.

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

Implementors§