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§
Required Methods§
Sourcefn load(
source: Self::Source,
cx: &mut App,
) -> impl Future<Output = Self::Output> + Send + 'static
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".