#Custom asset with lifetime?

6 messages · Page 1 of 1 (latest)

sand hamlet
#

I'm trying to create a custom asset that contains a Cow<'a, str>. Cow requires specifying a lifetime attribute:

#[derive(Debug, Default, Clone, Serialize, Deserialize, TypeUuid, TypePath)]
#[uuid = "4af40b07-f427-46f5-bdb2-f4b6f6c8ccef"]
pub struct StyleCatalog<'a> {
    #[serde(flatten)]
    styles: HashMap<Cow<'a, str>, Arc<Style<'static>>>,
}

However, the compiler won't let me derive TypePath here. The error I get is lifetime bound not satisfied but lifetime parameter must outlive the static lifetime.

Are there any examples of a custom asset that has a lifetime parameter?

harsh hedge
#

it's not possible as the asset is stored in the world

#

Only things with static lifetimes can be stored there

sand hamlet
#

The only thing that puzzles me is, what happens when an asset gets uncached? It's not really static, is it?

harsh hedge
#

Handle is basically a smart pointer, so it gets dropped once the last strong Handle is dropped. (technically 2 frames after to avoid dropping and reloading an asset). Would also get dropped if the World gets dropped.

It's more that the lifetime of an asset can't be determined at compile time, so bevy can only accept the least restrictive lifetime i.e. 'static