Skip to content

Commit

Permalink
merge nothing?
Browse files Browse the repository at this point in the history
  • Loading branch information
soqb committed Jan 30, 2024
2 parents 451b2a8 + ad0af31 commit 2215ee2
Showing 1 changed file with 24 additions and 12 deletions.
36 changes: 24 additions & 12 deletions crates/bevy_asset/src/saver.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
use crate::{io::Writer, meta::Settings, Asset, ErasedLoadedAsset};
use crate::{AssetLoader, LabeledAsset};
use crate::{AssetLoader, LabeledAsset, UntypedHandle};
use bevy_utils::{BoxedFuture, CowArc, HashMap};
use serde::{Deserialize, Serialize};
use std::ops::Deref;
use std::{borrow::Borrow, hash::Hash, ops::Deref};

/// Saves an [`Asset`] of a given [`AssetSaver::Asset`] type. [`AssetSaver::OutputLoader`] will then be used to load the saved asset
/// in the final deployed application. The saver should produce asset bytes in a format that [`AssetSaver::OutputLoader`] can read.
Expand Down Expand Up @@ -95,11 +95,12 @@ impl<'a, A: Asset> SavedAsset<'a, A> {
}

/// Returns the labeled asset, if it exists and matches this type.
pub fn get_labeled<B: Asset>(
&self,
label: impl Into<CowArc<'static, str>>,
) -> Option<SavedAsset<B>> {
let labeled = self.labeled_assets.get(&label.into())?;
pub fn get_labeled<B: Asset, Q>(&self, label: &Q) -> Option<SavedAsset<B>>
where
CowArc<'static, str>: Borrow<Q>,
Q: ?Sized + Hash + Eq,
{
let labeled = self.labeled_assets.get(label)?;
let value = labeled.asset.value.downcast_ref::<B>()?;
Some(SavedAsset {
value,
Expand All @@ -108,14 +109,25 @@ impl<'a, A: Asset> SavedAsset<'a, A> {
}

/// Returns the type-erased labeled asset, if it exists and matches this type.
pub fn get_erased_labeled(
&self,
label: impl Into<CowArc<'static, str>>,
) -> Option<&ErasedLoadedAsset> {
let labeled = self.labeled_assets.get(&label.into())?;
pub fn get_erased_labeled<Q>(&self, label: &Q) -> Option<&ErasedLoadedAsset>
where
CowArc<'static, str>: Borrow<Q>,
Q: ?Sized + Hash + Eq,
{
let labeled = self.labeled_assets.get(label)?;
Some(&labeled.asset)
}

/// Returns the [`UntypedHandle`] of the labeled asset with the provided 'label', if it exists.
pub fn get_untyped_handle<Q>(&self, label: &Q) -> Option<&UntypedHandle>
where
CowArc<'static, str>: Borrow<Q>,
Q: ?Sized + Hash + Eq,
{
let labeled = self.labeled_assets.get(label)?;
Some(&labeled.handle)
}

/// Iterate over all labels for "labeled assets" in the loaded asset
pub fn iter_labels(&self) -> impl Iterator<Item = &str> {
self.labeled_assets.keys().map(|s| &**s)
Expand Down

0 comments on commit 2215ee2

Please sign in to comment.