From 49761943e2a854f91bd7dec0ec5ab818b9e6f70d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9l=C3=A8ne=20Amanita?= Date: Thu, 9 Nov 2023 01:31:53 +0000 Subject: [PATCH 1/7] Fix Handle TypeId mismatch when using labels --- crates/bevy_asset/src/lib.rs | 10 +- crates/bevy_asset/src/loader.rs | 26 ++++- crates/bevy_asset/src/meta.rs | 10 ++ crates/bevy_asset/src/path.rs | 94 ++++++++++++++++--- crates/bevy_asset/src/server/mod.rs | 21 ++++- crates/bevy_audio/src/audio_source.rs | 10 +- crates/bevy_gltf/src/loader.rs | 36 ++++++- .../bevy_render/src/render_resource/shader.rs | 10 +- .../src/texture/hdr_texture_loader.rs | 10 ++ .../bevy_render/src/texture/image_loader.rs | 10 ++ crates/bevy_scene/src/scene_loader.rs | 10 ++ crates/bevy_text/src/font_loader.rs | 10 ++ 12 files changed, 238 insertions(+), 19 deletions(-) diff --git a/crates/bevy_asset/src/lib.rs b/crates/bevy_asset/src/lib.rs index 9f9cd44c77b0d..03388736c67a7 100644 --- a/crates/bevy_asset/src/lib.rs +++ b/crates/bevy_asset/src/lib.rs @@ -415,7 +415,7 @@ mod tests { use bevy_utils::BoxedFuture; use futures_lite::AsyncReadExt; use serde::{Deserialize, Serialize}; - use std::path::Path; + use std::{any::TypeId, path::Path}; use thiserror::Error; #[derive(Asset, TypePath, Debug)] @@ -501,6 +501,14 @@ mod tests { fn extensions(&self) -> &[&str] { &["cool.ron"] } + + fn label_type_name(&self, _label_type: &str) -> Option<&'static str> { + Some(std::any::type_name::()) + } + + fn label_type_id(&self, _label_type: &str) -> Option { + Some(TypeId::of::()) + } } fn test_app(dir: Dir) -> (App, GateOpener) { diff --git a/crates/bevy_asset/src/loader.rs b/crates/bevy_asset/src/loader.rs index 3a5bbc7d032aa..d4ee0faebb43c 100644 --- a/crates/bevy_asset/src/loader.rs +++ b/crates/bevy_asset/src/loader.rs @@ -39,6 +39,10 @@ pub trait AssetLoader: Send + Sync + 'static { /// Returns a list of extensions supported by this asset loader, without the preceding dot. fn extensions(&self) -> &[&str]; + /// Returns the type name of the sub-asset type with the given `label`. + fn label_type_name(&self, label_type: &str) -> Option<&'static str>; + /// Returns the [`TypeId`] of the sub-asset type with the given `label``. + fn label_type_id(&self, label_type: &str) -> Option; } /// Provides type-erased access to an [`AssetLoader`]. @@ -68,6 +72,10 @@ pub trait ErasedAssetLoader: Send + Sync + 'static { fn asset_type_name(&self) -> &'static str; /// Returns the [`TypeId`] of the top-level [`Asset`] loaded by the [`AssetLoader`]. fn asset_type_id(&self) -> TypeId; + /// Returns the type name of the sub-asset type with the given `label`. + fn label_type_name(&self, label_type: Option<&str>) -> Option<&'static str>; + /// Returns the [`TypeId`] of the sub-asset type with the given `label`. + fn label_type_id(&self, label_type: Option<&str>) -> Option; } impl ErasedAssetLoader for L @@ -119,12 +127,26 @@ where TypeId::of::() } + fn asset_type_name(&self) -> &'static str { + std::any::type_name::() + } + fn asset_type_id(&self) -> TypeId { TypeId::of::() } - fn asset_type_name(&self) -> &'static str { - std::any::type_name::() + fn label_type_name(&self, label_type: Option<&str>) -> Option<&'static str> { + match label_type { + None => Some(self.asset_type_name()), + Some(label_type) => ::label_type_name(self, label_type), + } + } + + fn label_type_id(&self, label_type: Option<&str>) -> Option { + match label_type { + None => Some(self.asset_type_id()), + Some(label_type) => ::label_type_id(self, label_type), + } } } diff --git a/crates/bevy_asset/src/meta.rs b/crates/bevy_asset/src/meta.rs index dbcd7d7feb57d..7931b8b4608e3 100644 --- a/crates/bevy_asset/src/meta.rs +++ b/crates/bevy_asset/src/meta.rs @@ -1,3 +1,5 @@ +use std::any::TypeId; + use crate::{self as bevy_asset, DeserializeMetaError, VisitAssetDependencies}; use crate::{loader::AssetLoader, processor::Process, Asset, AssetPath}; use bevy_log::error; @@ -206,6 +208,14 @@ impl AssetLoader for () { fn extensions(&self) -> &[&str] { unreachable!(); } + + fn label_type_name(&self, _label_type: &str) -> Option<&'static str> { + unreachable!(); + } + + fn label_type_id(&self, _label_type: &str) -> Option { + unreachable!(); + } } pub(crate) fn loader_settings_meta_transform( diff --git a/crates/bevy_asset/src/path.rs b/crates/bevy_asset/src/path.rs index fccc0783f6249..94a2e83de3cae 100644 --- a/crates/bevy_asset/src/path.rs +++ b/crates/bevy_asset/src/path.rs @@ -52,11 +52,22 @@ use thiserror::Error; /// This means that the common case of `asset_server.load("my_scene.scn")` when it creates and /// clones internal owned [`AssetPaths`](AssetPath). /// This also means that you should use [`AssetPath::parse`] in cases where `&str` is the explicit type. -#[derive(Eq, PartialEq, Hash, Clone, Default)] +#[derive(Eq, Hash, Clone, Default)] pub struct AssetPath<'a> { source: AssetSourceId<'a>, path: CowArc<'a, Path>, label: Option>, + /// Last part of the asset label. + /// This is given as a convenience only when parsing an asset path string, + /// but it is not set when a `label` is set directly. + /// Should not be used for comparison. + pub(crate) label_type: Option>, +} + +impl<'a> PartialEq for AssetPath<'a> { + fn eq(&self, rhs: &Self) -> bool { + self.source == rhs.source && self.path == rhs.path && self.label == rhs.label + } } impl<'a> Debug for AssetPath<'a> { @@ -86,6 +97,8 @@ pub enum ParseAssetPathError { MissingSource, #[error("Asset label must be at least one character. Either specify the label after the '#' or remove the '#'")] MissingLabel, + #[error("Asset label shouldn't end with a '/', either remove it or add a sub-label after it")] + MissingEndLabel, } impl<'a> AssetPath<'a> { @@ -115,7 +128,7 @@ impl<'a> AssetPath<'a> { /// /// This will return a [`ParseAssetPathError`] if `asset_path` is in an invalid format. pub fn try_parse(asset_path: &'a str) -> Result, ParseAssetPathError> { - let (source, path, label) = Self::parse_internal(asset_path).unwrap(); + let (source, path, label, label_type) = Self::parse_internal(asset_path).unwrap(); Ok(Self { source: match source { Some(source) => AssetSourceId::Name(CowArc::Borrowed(source)), @@ -123,16 +136,18 @@ impl<'a> AssetPath<'a> { }, path: CowArc::Borrowed(path), label: label.map(CowArc::Borrowed), + label_type: label_type.map(CowArc::Borrowed), }) } fn parse_internal( asset_path: &str, - ) -> Result<(Option<&str>, &Path, Option<&str>), ParseAssetPathError> { + ) -> Result<(Option<&str>, &Path, Option<&str>, Option<&str>), ParseAssetPathError> { let mut chars = asset_path.char_indices(); let mut source_range = None; let mut path_range = 0..asset_path.len(); let mut label_range = None; + let mut label_type_range = None; while let Some((index, char)) = chars.next() { match char { ':' => { @@ -154,7 +169,17 @@ impl<'a> AssetPath<'a> { '#' => { path_range.end = index; label_range = Some(index + 1..asset_path.len()); - break; + label_type_range = label_range.clone(); + } + '/' => { + if label_range.is_some() { + label_type_range = Some(index + 1..asset_path.len()); + } + } + '0' | '1' | '2' | '3' | '4' | '5' | '6' | '7' | '8' | '9' => { + if let Some(ref mut label_type_range) = label_type_range { + label_type_range.end = index; + } } _ => {} } @@ -178,9 +203,18 @@ impl<'a> AssetPath<'a> { } None => None, }; + let label_type = match label_type_range { + Some(label_type_range) => { + if label_type_range.is_empty() { + return Err(ParseAssetPathError::MissingEndLabel); + } + Some(&asset_path[label_type_range]) + } + None => None, + }; let path = Path::new(&asset_path[path_range]); - Ok((source, path, label)) + Ok((source, path, label, label_type)) } /// Creates a new [`AssetPath`] from a [`Path`]. @@ -190,6 +224,7 @@ impl<'a> AssetPath<'a> { path: CowArc::Borrowed(path), source: AssetSourceId::Default, label: None, + label_type: None, } } @@ -212,6 +247,18 @@ impl<'a> AssetPath<'a> { self.label.clone() } + /// Gets the "sub-asset label type". + #[inline] + pub fn label_type(&self) -> Option<&str> { + self.label_type.as_deref() + } + + /// Gets the "sub-asset label type". + #[inline] + pub fn label_type_cow(&self) -> Option> { + self.label_type.clone() + } + /// Gets the path to the asset in the "virtual filesystem". #[inline] pub fn path(&self) -> &Path { @@ -225,6 +272,7 @@ impl<'a> AssetPath<'a> { source: self.source.clone(), path: self.path.clone(), label: None, + label_type: None, } } @@ -232,11 +280,13 @@ impl<'a> AssetPath<'a> { #[inline] pub fn remove_label(&mut self) { self.label = None; + self.label_type = None; } /// Takes the "sub-asset label" from this [`AssetPath`], if one was set. #[inline] pub fn take_label(&mut self) -> Option> { + self.label_type = None; self.label.take() } @@ -248,6 +298,7 @@ impl<'a> AssetPath<'a> { source: self.source, path: self.path, label: Some(label.into()), + label_type: None, } } @@ -259,6 +310,7 @@ impl<'a> AssetPath<'a> { source: source.into(), path: self.path, label: self.label, + label_type: self.label_type, } } @@ -272,6 +324,7 @@ impl<'a> AssetPath<'a> { Some(AssetPath { source: self.source.clone(), label: None, + label_type: None, path, }) } @@ -286,6 +339,7 @@ impl<'a> AssetPath<'a> { source: self.source.into_owned(), path: self.path.into_owned(), label: self.label.map(|l| l.into_owned()), + label_type: self.label_type.map(|l| l.into_owned()), } } @@ -375,7 +429,7 @@ impl<'a> AssetPath<'a> { // It's a label only Ok(self.clone_owned().with_label(label.to_owned())) } else { - let (source, rpath, rlabel) = AssetPath::parse_internal(path)?; + let (source, rpath, rlabel, rlabel_type) = AssetPath::parse_internal(path)?; let mut base_path = PathBuf::from(self.path()); if replace && !self.path.to_str().unwrap().ends_with('/') { // No error if base is empty (per RFC 1808). @@ -428,6 +482,7 @@ impl<'a> AssetPath<'a> { }, path: CowArc::Owned(result_path.into()), label: rlabel.map(|l| CowArc::Owned(l.into())), + label_type: rlabel_type.map(|l| CowArc::Owned(l.into())), }) } } @@ -455,11 +510,12 @@ impl<'a> AssetPath<'a> { impl From<&'static str> for AssetPath<'static> { #[inline] fn from(asset_path: &'static str) -> Self { - let (source, path, label) = Self::parse_internal(asset_path).unwrap(); + let (source, path, label, label_type) = Self::parse_internal(asset_path).unwrap(); AssetPath { source: source.into(), path: CowArc::Static(path), label: label.map(CowArc::Static), + label_type: label_type.map(CowArc::Static), } } } @@ -485,6 +541,7 @@ impl From<&'static Path> for AssetPath<'static> { source: AssetSourceId::Default, path: CowArc::Static(path), label: None, + label_type: None, } } } @@ -496,6 +553,7 @@ impl From for AssetPath<'static> { source: AssetSourceId::Default, path: path.into(), label: None, + label_type: None, } } } @@ -693,19 +751,33 @@ mod tests { #[test] fn parse_asset_path() { let result = AssetPath::parse_internal("a/b.test"); - assert_eq!(result, Ok((None, Path::new("a/b.test"), None))); + assert_eq!(result, Ok((None, Path::new("a/b.test"), None, None))); let result = AssetPath::parse_internal("http://a/b.test"); - assert_eq!(result, Ok((Some("http"), Path::new("a/b.test"), None))); + assert_eq!( + result, + Ok((Some("http"), Path::new("a/b.test"), None, None)) + ); let result = AssetPath::parse_internal("http://a/b.test#Foo"); assert_eq!( result, - Ok((Some("http"), Path::new("a/b.test"), Some("Foo"))) + Ok(( + Some("http"), + Path::new("a/b.test"), + Some("Foo"), + Some("Foo") + )) + ); + + let result = AssetPath::parse_internal("a#Foo0/Bar1"); + assert_eq!( + result, + Ok((None, Path::new("a"), Some("Foo0/Bar1"), Some("Bar"))) ); let result = AssetPath::parse_internal("http://"); - assert_eq!(result, Ok((Some("http"), Path::new(""), None))); + assert_eq!(result, Ok((Some("http"), Path::new(""), None, None))); let result = AssetPath::parse_internal("://x"); assert_eq!(result, Err(crate::ParseAssetPathError::MissingSource)); diff --git a/crates/bevy_asset/src/server/mod.rs b/crates/bevy_asset/src/server/mod.rs index 864faf70fc71b..10e21eb6293f0 100644 --- a/crates/bevy_asset/src/server/mod.rs +++ b/crates/bevy_asset/src/server/mod.rs @@ -386,10 +386,21 @@ impl AssetServer { } None => { let mut infos = self.data.infos.write(); + let label_type = path.label_type(); + let (Some(type_id), Some(type_name)) = ( + loader.label_type_id(label_type), + loader.label_type_name(label_type), + ) else { + return Err(AssetLoadError::WrongLabel { + base_path: path.without_label().into_owned(), + label: path.label().unwrap_or_default().to_owned(), + label_type: label_type.unwrap_or_default().to_owned(), + }); + }; infos.get_or_create_path_handle_untyped( path.clone(), - loader.asset_type_id(), - loader.asset_type_name(), + type_id, + type_name, HandleLoadingMode::Request, meta_transform, ) @@ -1053,6 +1064,12 @@ pub enum AssetLoadError { base_path: AssetPath<'static>, label: String, }, + #[error("The type of the file at '{base_path}' does not support the label type '{label_type}' at the end of the label '{label}'.")] + WrongLabel { + base_path: AssetPath<'static>, + label: String, + label_type: String, + }, } /// An error that occurs when an [`AssetLoader`] is not registered for a given extension. diff --git a/crates/bevy_audio/src/audio_source.rs b/crates/bevy_audio/src/audio_source.rs index 30f9c8cf8da9e..e3c4f3c2a9e40 100644 --- a/crates/bevy_audio/src/audio_source.rs +++ b/crates/bevy_audio/src/audio_source.rs @@ -4,7 +4,7 @@ use bevy_asset::{ }; use bevy_reflect::TypePath; use bevy_utils::BoxedFuture; -use std::{io::Cursor, sync::Arc}; +use std::{any::TypeId, io::Cursor, sync::Arc}; /// A source of audio data #[derive(Asset, Debug, Clone, TypePath)] @@ -74,6 +74,14 @@ impl AssetLoader for AudioLoader { "spx", ] } + + fn label_type_name(&self, _label_type: &str) -> Option<&'static str> { + None + } + + fn label_type_id(&self, _label_type: &str) -> Option { + None + } } /// A type implementing this trait can be converted to a [`rodio::Source`] type. diff --git a/crates/bevy_gltf/src/loader.rs b/crates/bevy_gltf/src/loader.rs index abdbc1a3cbe50..9bb5ceaed65ed 100644 --- a/crates/bevy_gltf/src/loader.rs +++ b/crates/bevy_gltf/src/loader.rs @@ -1,4 +1,5 @@ -use crate::{vertex_attributes::convert_attribute, Gltf, GltfExtras, GltfNode}; +use crate::{vertex_attributes::convert_attribute, Gltf, GltfExtras, GltfMesh, GltfNode}; +use bevy_animation::AnimationClip; use bevy_asset::{ io::Reader, AssetLoadError, AssetLoader, AsyncReadExt, Handle, LoadContext, ReadAssetBytesError, }; @@ -41,6 +42,7 @@ use gltf::{ }; use serde::Deserialize; use std::{ + any::TypeId, collections::VecDeque, path::{Path, PathBuf}, }; @@ -125,6 +127,38 @@ impl AssetLoader for GltfLoader { fn extensions(&self) -> &[&str] { &["gltf", "glb"] } + + fn label_type_name(&self, label_type: &str) -> Option<&'static str> { + match label_type { + "Scene" => Some(std::any::type_name::()), + "Node" => Some(std::any::type_name::()), + "Mesh" => Some(std::any::type_name::()), + "Primitive" => Some(std::any::type_name::()), + //"MorphTarget" => Some(std::any::type_name::()), + "Texture" => Some(std::any::type_name::()), + "Material" => Some(std::any::type_name::()), + "DefaultMaterial" => Some(std::any::type_name::()), + "Animation" => Some(std::any::type_name::()), + "Skin" => Some(std::any::type_name::()), + _ => None, + } + } + + fn label_type_id(&self, label_type: &str) -> Option { + match label_type { + "Scene" => Some(TypeId::of::()), + "Node" => Some(TypeId::of::()), + "Mesh" => Some(TypeId::of::()), + "Primitive" => Some(TypeId::of::()), + //"MorphTarget" => Some(TypeId::of::()), + "Texture" => Some(TypeId::of::()), + "Material" => Some(TypeId::of::()), + "DefaultMaterial" => Some(TypeId::of::()), + "Animation" => Some(TypeId::of::()), + "Skin" => Some(TypeId::of::()), + _ => None, + } + } } /// Loads an entire glTF file. diff --git a/crates/bevy_render/src/render_resource/shader.rs b/crates/bevy_render/src/render_resource/shader.rs index 465fbb193d35a..099c0528b859a 100644 --- a/crates/bevy_render/src/render_resource/shader.rs +++ b/crates/bevy_render/src/render_resource/shader.rs @@ -4,7 +4,7 @@ use bevy_asset::{io::Reader, Asset, AssetLoader, AssetPath, Handle, LoadContext} use bevy_reflect::TypePath; use bevy_utils::{tracing::error, BoxedFuture}; use futures_lite::AsyncReadExt; -use std::{borrow::Cow, marker::Copy}; +use std::{any::TypeId, borrow::Cow, marker::Copy}; use thiserror::Error; define_atomic_id!(ShaderId); @@ -299,6 +299,14 @@ impl AssetLoader for ShaderLoader { fn extensions(&self) -> &[&str] { &["spv", "wgsl", "vert", "frag", "comp"] } + + fn label_type_name(&self, _label_type: &str) -> Option<&'static str> { + None + } + + fn label_type_id(&self, _label_type: &str) -> Option { + None + } } #[derive(Debug, PartialEq, Eq, Clone, Hash)] diff --git a/crates/bevy_render/src/texture/hdr_texture_loader.rs b/crates/bevy_render/src/texture/hdr_texture_loader.rs index e54b38b806606..aeabeac40dbd1 100644 --- a/crates/bevy_render/src/texture/hdr_texture_loader.rs +++ b/crates/bevy_render/src/texture/hdr_texture_loader.rs @@ -1,3 +1,5 @@ +use std::any::TypeId; + use crate::texture::{Image, TextureFormatPixelInfo}; use bevy_asset::{io::Reader, AssetLoader, AsyncReadExt, LoadContext}; use thiserror::Error; @@ -66,4 +68,12 @@ impl AssetLoader for HdrTextureLoader { fn extensions(&self) -> &[&str] { &["hdr"] } + + fn label_type_name(&self, _label_type: &str) -> Option<&'static str> { + None + } + + fn label_type_id(&self, _label_type: &str) -> Option { + None + } } diff --git a/crates/bevy_render/src/texture/image_loader.rs b/crates/bevy_render/src/texture/image_loader.rs index ec79c9d13e4cb..4ce8c91b6f643 100644 --- a/crates/bevy_render/src/texture/image_loader.rs +++ b/crates/bevy_render/src/texture/image_loader.rs @@ -1,3 +1,5 @@ +use std::any::TypeId; + use bevy_asset::{io::Reader, AssetLoader, AsyncReadExt, LoadContext}; use bevy_ecs::prelude::{FromWorld, World}; use thiserror::Error; @@ -115,6 +117,14 @@ impl AssetLoader for ImageLoader { fn extensions(&self) -> &[&str] { IMG_FILE_EXTENSIONS } + + fn label_type_name(&self, _label_type: &str) -> Option<&'static str> { + None + } + + fn label_type_id(&self, _label_type: &str) -> Option { + None + } } impl FromWorld for ImageLoader { diff --git a/crates/bevy_scene/src/scene_loader.rs b/crates/bevy_scene/src/scene_loader.rs index 5d1e4de56ade4..213e226ceacb2 100644 --- a/crates/bevy_scene/src/scene_loader.rs +++ b/crates/bevy_scene/src/scene_loader.rs @@ -1,3 +1,5 @@ +use std::any::TypeId; + #[cfg(feature = "serialize")] use crate::serde::SceneDeserializer; use crate::DynamicScene; @@ -65,4 +67,12 @@ impl AssetLoader for SceneLoader { fn extensions(&self) -> &[&str] { &["scn", "scn.ron"] } + + fn label_type_name(&self, _label_type: &str) -> Option<&'static str> { + None + } + + fn label_type_id(&self, _label_type: &str) -> Option { + None + } } diff --git a/crates/bevy_text/src/font_loader.rs b/crates/bevy_text/src/font_loader.rs index a47abbd9619a0..59966da4c56fa 100644 --- a/crates/bevy_text/src/font_loader.rs +++ b/crates/bevy_text/src/font_loader.rs @@ -1,3 +1,5 @@ +use std::any::TypeId; + use crate::Font; use bevy_asset::{io::Reader, AssetLoader, AsyncReadExt, LoadContext}; use thiserror::Error; @@ -37,4 +39,12 @@ impl AssetLoader for FontLoader { fn extensions(&self) -> &[&str] { &["ttf", "otf"] } + + fn label_type_name(&self, _label_type: &str) -> Option<&'static str> { + None + } + + fn label_type_id(&self, _label_type: &str) -> Option { + None + } } From e6591bbbada29030566f73f307a7a2beff1daece Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9l=C3=A8ne=20Amanita?= Date: Thu, 9 Nov 2023 01:58:32 +0000 Subject: [PATCH 2/7] CI --- crates/bevy_asset/src/loader.rs | 2 +- crates/bevy_render/src/texture/exr_texture_loader.rs | 8 ++++++++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/crates/bevy_asset/src/loader.rs b/crates/bevy_asset/src/loader.rs index d4ee0faebb43c..ca647191c3114 100644 --- a/crates/bevy_asset/src/loader.rs +++ b/crates/bevy_asset/src/loader.rs @@ -41,7 +41,7 @@ pub trait AssetLoader: Send + Sync + 'static { fn extensions(&self) -> &[&str]; /// Returns the type name of the sub-asset type with the given `label`. fn label_type_name(&self, label_type: &str) -> Option<&'static str>; - /// Returns the [`TypeId`] of the sub-asset type with the given `label``. + /// Returns the [`TypeId`] of the sub-asset type with the given `label`. fn label_type_id(&self, label_type: &str) -> Option; } diff --git a/crates/bevy_render/src/texture/exr_texture_loader.rs b/crates/bevy_render/src/texture/exr_texture_loader.rs index e5494e9935d52..5aef7761d8d66 100644 --- a/crates/bevy_render/src/texture/exr_texture_loader.rs +++ b/crates/bevy_render/src/texture/exr_texture_loader.rs @@ -70,4 +70,12 @@ impl AssetLoader for ExrTextureLoader { fn extensions(&self) -> &[&str] { &["exr"] } + + fn label_type_name(&self, _label_type: &str) -> Option<&'static str> { + None + } + + fn label_type_id(&self, _label_type: &str) -> Option { + None + } } From 312799cadd1fdf317eeea9fe922fd1b0d011652e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9l=C3=A8ne=20Amanita?= Date: Thu, 9 Nov 2023 02:02:09 +0000 Subject: [PATCH 3/7] CI-2 --- crates/bevy_render/src/texture/exr_texture_loader.rs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/crates/bevy_render/src/texture/exr_texture_loader.rs b/crates/bevy_render/src/texture/exr_texture_loader.rs index 5aef7761d8d66..83f8fe775b241 100644 --- a/crates/bevy_render/src/texture/exr_texture_loader.rs +++ b/crates/bevy_render/src/texture/exr_texture_loader.rs @@ -1,3 +1,5 @@ +use std::any::TypeId; + use crate::texture::{Image, TextureFormatPixelInfo}; use bevy_asset::{ io::{AsyncReadExt, Reader}, From 52bd5276fb3fe719efe24489c8fac88a0d06722d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9l=C3=A8ne=20Amanita?= Date: Thu, 9 Nov 2023 11:40:21 +0000 Subject: [PATCH 4/7] Don't preemptively parse the label --- crates/bevy_asset/src/loader.rs | 24 +++++--- crates/bevy_asset/src/path.rs | 94 ++++------------------------- crates/bevy_asset/src/server/mod.rs | 15 ++--- crates/bevy_gltf/src/loader.rs | 26 ++++++-- 4 files changed, 51 insertions(+), 108 deletions(-) diff --git a/crates/bevy_asset/src/loader.rs b/crates/bevy_asset/src/loader.rs index ca647191c3114..d4d100117522e 100644 --- a/crates/bevy_asset/src/loader.rs +++ b/crates/bevy_asset/src/loader.rs @@ -40,9 +40,13 @@ pub trait AssetLoader: Send + Sync + 'static { /// Returns a list of extensions supported by this asset loader, without the preceding dot. fn extensions(&self) -> &[&str]; /// Returns the type name of the sub-asset type with the given `label`. - fn label_type_name(&self, label_type: &str) -> Option<&'static str>; + fn label_type_name(&self, #[allow(unused_variables)] label: &str) -> Option<&'static str> { + None + } /// Returns the [`TypeId`] of the sub-asset type with the given `label`. - fn label_type_id(&self, label_type: &str) -> Option; + fn label_type_id(&self, #[allow(unused_variables)] label: &str) -> Option { + None + } } /// Provides type-erased access to an [`AssetLoader`]. @@ -73,9 +77,9 @@ pub trait ErasedAssetLoader: Send + Sync + 'static { /// Returns the [`TypeId`] of the top-level [`Asset`] loaded by the [`AssetLoader`]. fn asset_type_id(&self) -> TypeId; /// Returns the type name of the sub-asset type with the given `label`. - fn label_type_name(&self, label_type: Option<&str>) -> Option<&'static str>; + fn label_type_name(&self, label: Option<&str>) -> Option<&'static str>; /// Returns the [`TypeId`] of the sub-asset type with the given `label`. - fn label_type_id(&self, label_type: Option<&str>) -> Option; + fn label_type_id(&self, label: Option<&str>) -> Option; } impl ErasedAssetLoader for L @@ -135,17 +139,17 @@ where TypeId::of::() } - fn label_type_name(&self, label_type: Option<&str>) -> Option<&'static str> { - match label_type { + fn label_type_name(&self, label: Option<&str>) -> Option<&'static str> { + match label { None => Some(self.asset_type_name()), - Some(label_type) => ::label_type_name(self, label_type), + Some(label) => ::label_type_name(self, label), } } - fn label_type_id(&self, label_type: Option<&str>) -> Option { - match label_type { + fn label_type_id(&self, label: Option<&str>) -> Option { + match label { None => Some(self.asset_type_id()), - Some(label_type) => ::label_type_id(self, label_type), + Some(label) => ::label_type_id(self, label), } } } diff --git a/crates/bevy_asset/src/path.rs b/crates/bevy_asset/src/path.rs index 94a2e83de3cae..fccc0783f6249 100644 --- a/crates/bevy_asset/src/path.rs +++ b/crates/bevy_asset/src/path.rs @@ -52,22 +52,11 @@ use thiserror::Error; /// This means that the common case of `asset_server.load("my_scene.scn")` when it creates and /// clones internal owned [`AssetPaths`](AssetPath). /// This also means that you should use [`AssetPath::parse`] in cases where `&str` is the explicit type. -#[derive(Eq, Hash, Clone, Default)] +#[derive(Eq, PartialEq, Hash, Clone, Default)] pub struct AssetPath<'a> { source: AssetSourceId<'a>, path: CowArc<'a, Path>, label: Option>, - /// Last part of the asset label. - /// This is given as a convenience only when parsing an asset path string, - /// but it is not set when a `label` is set directly. - /// Should not be used for comparison. - pub(crate) label_type: Option>, -} - -impl<'a> PartialEq for AssetPath<'a> { - fn eq(&self, rhs: &Self) -> bool { - self.source == rhs.source && self.path == rhs.path && self.label == rhs.label - } } impl<'a> Debug for AssetPath<'a> { @@ -97,8 +86,6 @@ pub enum ParseAssetPathError { MissingSource, #[error("Asset label must be at least one character. Either specify the label after the '#' or remove the '#'")] MissingLabel, - #[error("Asset label shouldn't end with a '/', either remove it or add a sub-label after it")] - MissingEndLabel, } impl<'a> AssetPath<'a> { @@ -128,7 +115,7 @@ impl<'a> AssetPath<'a> { /// /// This will return a [`ParseAssetPathError`] if `asset_path` is in an invalid format. pub fn try_parse(asset_path: &'a str) -> Result, ParseAssetPathError> { - let (source, path, label, label_type) = Self::parse_internal(asset_path).unwrap(); + let (source, path, label) = Self::parse_internal(asset_path).unwrap(); Ok(Self { source: match source { Some(source) => AssetSourceId::Name(CowArc::Borrowed(source)), @@ -136,18 +123,16 @@ impl<'a> AssetPath<'a> { }, path: CowArc::Borrowed(path), label: label.map(CowArc::Borrowed), - label_type: label_type.map(CowArc::Borrowed), }) } fn parse_internal( asset_path: &str, - ) -> Result<(Option<&str>, &Path, Option<&str>, Option<&str>), ParseAssetPathError> { + ) -> Result<(Option<&str>, &Path, Option<&str>), ParseAssetPathError> { let mut chars = asset_path.char_indices(); let mut source_range = None; let mut path_range = 0..asset_path.len(); let mut label_range = None; - let mut label_type_range = None; while let Some((index, char)) = chars.next() { match char { ':' => { @@ -169,17 +154,7 @@ impl<'a> AssetPath<'a> { '#' => { path_range.end = index; label_range = Some(index + 1..asset_path.len()); - label_type_range = label_range.clone(); - } - '/' => { - if label_range.is_some() { - label_type_range = Some(index + 1..asset_path.len()); - } - } - '0' | '1' | '2' | '3' | '4' | '5' | '6' | '7' | '8' | '9' => { - if let Some(ref mut label_type_range) = label_type_range { - label_type_range.end = index; - } + break; } _ => {} } @@ -203,18 +178,9 @@ impl<'a> AssetPath<'a> { } None => None, }; - let label_type = match label_type_range { - Some(label_type_range) => { - if label_type_range.is_empty() { - return Err(ParseAssetPathError::MissingEndLabel); - } - Some(&asset_path[label_type_range]) - } - None => None, - }; let path = Path::new(&asset_path[path_range]); - Ok((source, path, label, label_type)) + Ok((source, path, label)) } /// Creates a new [`AssetPath`] from a [`Path`]. @@ -224,7 +190,6 @@ impl<'a> AssetPath<'a> { path: CowArc::Borrowed(path), source: AssetSourceId::Default, label: None, - label_type: None, } } @@ -247,18 +212,6 @@ impl<'a> AssetPath<'a> { self.label.clone() } - /// Gets the "sub-asset label type". - #[inline] - pub fn label_type(&self) -> Option<&str> { - self.label_type.as_deref() - } - - /// Gets the "sub-asset label type". - #[inline] - pub fn label_type_cow(&self) -> Option> { - self.label_type.clone() - } - /// Gets the path to the asset in the "virtual filesystem". #[inline] pub fn path(&self) -> &Path { @@ -272,7 +225,6 @@ impl<'a> AssetPath<'a> { source: self.source.clone(), path: self.path.clone(), label: None, - label_type: None, } } @@ -280,13 +232,11 @@ impl<'a> AssetPath<'a> { #[inline] pub fn remove_label(&mut self) { self.label = None; - self.label_type = None; } /// Takes the "sub-asset label" from this [`AssetPath`], if one was set. #[inline] pub fn take_label(&mut self) -> Option> { - self.label_type = None; self.label.take() } @@ -298,7 +248,6 @@ impl<'a> AssetPath<'a> { source: self.source, path: self.path, label: Some(label.into()), - label_type: None, } } @@ -310,7 +259,6 @@ impl<'a> AssetPath<'a> { source: source.into(), path: self.path, label: self.label, - label_type: self.label_type, } } @@ -324,7 +272,6 @@ impl<'a> AssetPath<'a> { Some(AssetPath { source: self.source.clone(), label: None, - label_type: None, path, }) } @@ -339,7 +286,6 @@ impl<'a> AssetPath<'a> { source: self.source.into_owned(), path: self.path.into_owned(), label: self.label.map(|l| l.into_owned()), - label_type: self.label_type.map(|l| l.into_owned()), } } @@ -429,7 +375,7 @@ impl<'a> AssetPath<'a> { // It's a label only Ok(self.clone_owned().with_label(label.to_owned())) } else { - let (source, rpath, rlabel, rlabel_type) = AssetPath::parse_internal(path)?; + let (source, rpath, rlabel) = AssetPath::parse_internal(path)?; let mut base_path = PathBuf::from(self.path()); if replace && !self.path.to_str().unwrap().ends_with('/') { // No error if base is empty (per RFC 1808). @@ -482,7 +428,6 @@ impl<'a> AssetPath<'a> { }, path: CowArc::Owned(result_path.into()), label: rlabel.map(|l| CowArc::Owned(l.into())), - label_type: rlabel_type.map(|l| CowArc::Owned(l.into())), }) } } @@ -510,12 +455,11 @@ impl<'a> AssetPath<'a> { impl From<&'static str> for AssetPath<'static> { #[inline] fn from(asset_path: &'static str) -> Self { - let (source, path, label, label_type) = Self::parse_internal(asset_path).unwrap(); + let (source, path, label) = Self::parse_internal(asset_path).unwrap(); AssetPath { source: source.into(), path: CowArc::Static(path), label: label.map(CowArc::Static), - label_type: label_type.map(CowArc::Static), } } } @@ -541,7 +485,6 @@ impl From<&'static Path> for AssetPath<'static> { source: AssetSourceId::Default, path: CowArc::Static(path), label: None, - label_type: None, } } } @@ -553,7 +496,6 @@ impl From for AssetPath<'static> { source: AssetSourceId::Default, path: path.into(), label: None, - label_type: None, } } } @@ -751,33 +693,19 @@ mod tests { #[test] fn parse_asset_path() { let result = AssetPath::parse_internal("a/b.test"); - assert_eq!(result, Ok((None, Path::new("a/b.test"), None, None))); + assert_eq!(result, Ok((None, Path::new("a/b.test"), None))); let result = AssetPath::parse_internal("http://a/b.test"); - assert_eq!( - result, - Ok((Some("http"), Path::new("a/b.test"), None, None)) - ); + assert_eq!(result, Ok((Some("http"), Path::new("a/b.test"), None))); let result = AssetPath::parse_internal("http://a/b.test#Foo"); assert_eq!( result, - Ok(( - Some("http"), - Path::new("a/b.test"), - Some("Foo"), - Some("Foo") - )) - ); - - let result = AssetPath::parse_internal("a#Foo0/Bar1"); - assert_eq!( - result, - Ok((None, Path::new("a"), Some("Foo0/Bar1"), Some("Bar"))) + Ok((Some("http"), Path::new("a/b.test"), Some("Foo"))) ); let result = AssetPath::parse_internal("http://"); - assert_eq!(result, Ok((Some("http"), Path::new(""), None, None))); + assert_eq!(result, Ok((Some("http"), Path::new(""), None))); let result = AssetPath::parse_internal("://x"); assert_eq!(result, Err(crate::ParseAssetPathError::MissingSource)); diff --git a/crates/bevy_asset/src/server/mod.rs b/crates/bevy_asset/src/server/mod.rs index 10e21eb6293f0..8bf3bb60305bf 100644 --- a/crates/bevy_asset/src/server/mod.rs +++ b/crates/bevy_asset/src/server/mod.rs @@ -386,15 +386,13 @@ impl AssetServer { } None => { let mut infos = self.data.infos.write(); - let label_type = path.label_type(); - let (Some(type_id), Some(type_name)) = ( - loader.label_type_id(label_type), - loader.label_type_name(label_type), - ) else { + let label = path.label(); + let (Some(type_id), Some(type_name)) = + (loader.label_type_id(label), loader.label_type_name(label)) + else { return Err(AssetLoadError::WrongLabel { base_path: path.without_label().into_owned(), - label: path.label().unwrap_or_default().to_owned(), - label_type: label_type.unwrap_or_default().to_owned(), + label: label.unwrap_or_default().to_owned(), }); }; infos.get_or_create_path_handle_untyped( @@ -1064,11 +1062,10 @@ pub enum AssetLoadError { base_path: AssetPath<'static>, label: String, }, - #[error("The type of the file at '{base_path}' does not support the label type '{label_type}' at the end of the label '{label}'.")] + #[error("The type of the file at '{base_path}' does not support the label format '{label}'.")] WrongLabel { base_path: AssetPath<'static>, label: String, - label_type: String, }, } diff --git a/crates/bevy_gltf/src/loader.rs b/crates/bevy_gltf/src/loader.rs index 9bb5ceaed65ed..5d60745f68463 100644 --- a/crates/bevy_gltf/src/loader.rs +++ b/crates/bevy_gltf/src/loader.rs @@ -128,8 +128,8 @@ impl AssetLoader for GltfLoader { &["gltf", "glb"] } - fn label_type_name(&self, label_type: &str) -> Option<&'static str> { - match label_type { + fn label_type_name(&self, label: &str) -> Option<&'static str> { + match label_type(label) { "Scene" => Some(std::any::type_name::()), "Node" => Some(std::any::type_name::()), "Mesh" => Some(std::any::type_name::()), @@ -144,16 +144,15 @@ impl AssetLoader for GltfLoader { } } - fn label_type_id(&self, label_type: &str) -> Option { - match label_type { + fn label_type_id(&self, label: &str) -> Option { + match label_type(label) { "Scene" => Some(TypeId::of::()), "Node" => Some(TypeId::of::()), "Mesh" => Some(TypeId::of::()), "Primitive" => Some(TypeId::of::()), //"MorphTarget" => Some(TypeId::of::()), "Texture" => Some(TypeId::of::()), - "Material" => Some(TypeId::of::()), - "DefaultMaterial" => Some(TypeId::of::()), + "Material" | "DefaultMaterial" => Some(TypeId::of::()), "Animation" => Some(TypeId::of::()), "Skin" => Some(TypeId::of::()), _ => None, @@ -161,6 +160,21 @@ impl AssetLoader for GltfLoader { } } +fn label_type(label: &str) -> &str { + let mut label_type_range = 0..label.len(); + for (index, char) in label.char_indices() { + match char { + '/' => label_type_range = index + 1..label.len(), + '0' | '1' | '2' | '3' | '4' | '5' | '6' | '7' | '8' | '9' => { + label_type_range.end = index; + } + _ => (), + } + } + + &label[label_type_range] +} + /// Loads an entire glTF file. async fn load_gltf<'a, 'b, 'c>( loader: &GltfLoader, From 12d16252a2376a8ce6ea30da3e32055b6725a7e4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9l=C3=A8ne=20Amanita?= Date: Thu, 9 Nov 2023 11:48:26 +0000 Subject: [PATCH 5/7] CI --- crates/bevy_gltf/src/loader.rs | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/crates/bevy_gltf/src/loader.rs b/crates/bevy_gltf/src/loader.rs index 5d60745f68463..10465097503ce 100644 --- a/crates/bevy_gltf/src/loader.rs +++ b/crates/bevy_gltf/src/loader.rs @@ -136,8 +136,7 @@ impl AssetLoader for GltfLoader { "Primitive" => Some(std::any::type_name::()), //"MorphTarget" => Some(std::any::type_name::()), "Texture" => Some(std::any::type_name::()), - "Material" => Some(std::any::type_name::()), - "DefaultMaterial" => Some(std::any::type_name::()), + "Material" | "DefaultMaterial" => Some(std::any::type_name::()), "Animation" => Some(std::any::type_name::()), "Skin" => Some(std::any::type_name::()), _ => None, From 1a4026cdef20ddc53bdd9fddc602388b62f69722 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9l=C3=A8ne=20Amanita?= Date: Thu, 9 Nov 2023 11:53:40 +0000 Subject: [PATCH 6/7] Remove unnecessary implementations --- crates/bevy_asset/src/meta.rs | 10 ---------- crates/bevy_audio/src/audio_source.rs | 10 +--------- crates/bevy_render/src/render_resource/shader.rs | 10 +--------- crates/bevy_render/src/texture/exr_texture_loader.rs | 10 ---------- crates/bevy_render/src/texture/hdr_texture_loader.rs | 10 ---------- crates/bevy_render/src/texture/image_loader.rs | 10 ---------- crates/bevy_scene/src/scene_loader.rs | 10 ---------- crates/bevy_text/src/font_loader.rs | 10 ---------- 8 files changed, 2 insertions(+), 78 deletions(-) diff --git a/crates/bevy_asset/src/meta.rs b/crates/bevy_asset/src/meta.rs index 7931b8b4608e3..dbcd7d7feb57d 100644 --- a/crates/bevy_asset/src/meta.rs +++ b/crates/bevy_asset/src/meta.rs @@ -1,5 +1,3 @@ -use std::any::TypeId; - use crate::{self as bevy_asset, DeserializeMetaError, VisitAssetDependencies}; use crate::{loader::AssetLoader, processor::Process, Asset, AssetPath}; use bevy_log::error; @@ -208,14 +206,6 @@ impl AssetLoader for () { fn extensions(&self) -> &[&str] { unreachable!(); } - - fn label_type_name(&self, _label_type: &str) -> Option<&'static str> { - unreachable!(); - } - - fn label_type_id(&self, _label_type: &str) -> Option { - unreachable!(); - } } pub(crate) fn loader_settings_meta_transform( diff --git a/crates/bevy_audio/src/audio_source.rs b/crates/bevy_audio/src/audio_source.rs index e3c4f3c2a9e40..30f9c8cf8da9e 100644 --- a/crates/bevy_audio/src/audio_source.rs +++ b/crates/bevy_audio/src/audio_source.rs @@ -4,7 +4,7 @@ use bevy_asset::{ }; use bevy_reflect::TypePath; use bevy_utils::BoxedFuture; -use std::{any::TypeId, io::Cursor, sync::Arc}; +use std::{io::Cursor, sync::Arc}; /// A source of audio data #[derive(Asset, Debug, Clone, TypePath)] @@ -74,14 +74,6 @@ impl AssetLoader for AudioLoader { "spx", ] } - - fn label_type_name(&self, _label_type: &str) -> Option<&'static str> { - None - } - - fn label_type_id(&self, _label_type: &str) -> Option { - None - } } /// A type implementing this trait can be converted to a [`rodio::Source`] type. diff --git a/crates/bevy_render/src/render_resource/shader.rs b/crates/bevy_render/src/render_resource/shader.rs index 099c0528b859a..465fbb193d35a 100644 --- a/crates/bevy_render/src/render_resource/shader.rs +++ b/crates/bevy_render/src/render_resource/shader.rs @@ -4,7 +4,7 @@ use bevy_asset::{io::Reader, Asset, AssetLoader, AssetPath, Handle, LoadContext} use bevy_reflect::TypePath; use bevy_utils::{tracing::error, BoxedFuture}; use futures_lite::AsyncReadExt; -use std::{any::TypeId, borrow::Cow, marker::Copy}; +use std::{borrow::Cow, marker::Copy}; use thiserror::Error; define_atomic_id!(ShaderId); @@ -299,14 +299,6 @@ impl AssetLoader for ShaderLoader { fn extensions(&self) -> &[&str] { &["spv", "wgsl", "vert", "frag", "comp"] } - - fn label_type_name(&self, _label_type: &str) -> Option<&'static str> { - None - } - - fn label_type_id(&self, _label_type: &str) -> Option { - None - } } #[derive(Debug, PartialEq, Eq, Clone, Hash)] diff --git a/crates/bevy_render/src/texture/exr_texture_loader.rs b/crates/bevy_render/src/texture/exr_texture_loader.rs index 83f8fe775b241..e5494e9935d52 100644 --- a/crates/bevy_render/src/texture/exr_texture_loader.rs +++ b/crates/bevy_render/src/texture/exr_texture_loader.rs @@ -1,5 +1,3 @@ -use std::any::TypeId; - use crate::texture::{Image, TextureFormatPixelInfo}; use bevy_asset::{ io::{AsyncReadExt, Reader}, @@ -72,12 +70,4 @@ impl AssetLoader for ExrTextureLoader { fn extensions(&self) -> &[&str] { &["exr"] } - - fn label_type_name(&self, _label_type: &str) -> Option<&'static str> { - None - } - - fn label_type_id(&self, _label_type: &str) -> Option { - None - } } diff --git a/crates/bevy_render/src/texture/hdr_texture_loader.rs b/crates/bevy_render/src/texture/hdr_texture_loader.rs index aeabeac40dbd1..e54b38b806606 100644 --- a/crates/bevy_render/src/texture/hdr_texture_loader.rs +++ b/crates/bevy_render/src/texture/hdr_texture_loader.rs @@ -1,5 +1,3 @@ -use std::any::TypeId; - use crate::texture::{Image, TextureFormatPixelInfo}; use bevy_asset::{io::Reader, AssetLoader, AsyncReadExt, LoadContext}; use thiserror::Error; @@ -68,12 +66,4 @@ impl AssetLoader for HdrTextureLoader { fn extensions(&self) -> &[&str] { &["hdr"] } - - fn label_type_name(&self, _label_type: &str) -> Option<&'static str> { - None - } - - fn label_type_id(&self, _label_type: &str) -> Option { - None - } } diff --git a/crates/bevy_render/src/texture/image_loader.rs b/crates/bevy_render/src/texture/image_loader.rs index 4ce8c91b6f643..ec79c9d13e4cb 100644 --- a/crates/bevy_render/src/texture/image_loader.rs +++ b/crates/bevy_render/src/texture/image_loader.rs @@ -1,5 +1,3 @@ -use std::any::TypeId; - use bevy_asset::{io::Reader, AssetLoader, AsyncReadExt, LoadContext}; use bevy_ecs::prelude::{FromWorld, World}; use thiserror::Error; @@ -117,14 +115,6 @@ impl AssetLoader for ImageLoader { fn extensions(&self) -> &[&str] { IMG_FILE_EXTENSIONS } - - fn label_type_name(&self, _label_type: &str) -> Option<&'static str> { - None - } - - fn label_type_id(&self, _label_type: &str) -> Option { - None - } } impl FromWorld for ImageLoader { diff --git a/crates/bevy_scene/src/scene_loader.rs b/crates/bevy_scene/src/scene_loader.rs index 213e226ceacb2..5d1e4de56ade4 100644 --- a/crates/bevy_scene/src/scene_loader.rs +++ b/crates/bevy_scene/src/scene_loader.rs @@ -1,5 +1,3 @@ -use std::any::TypeId; - #[cfg(feature = "serialize")] use crate::serde::SceneDeserializer; use crate::DynamicScene; @@ -67,12 +65,4 @@ impl AssetLoader for SceneLoader { fn extensions(&self) -> &[&str] { &["scn", "scn.ron"] } - - fn label_type_name(&self, _label_type: &str) -> Option<&'static str> { - None - } - - fn label_type_id(&self, _label_type: &str) -> Option { - None - } } diff --git a/crates/bevy_text/src/font_loader.rs b/crates/bevy_text/src/font_loader.rs index 59966da4c56fa..a47abbd9619a0 100644 --- a/crates/bevy_text/src/font_loader.rs +++ b/crates/bevy_text/src/font_loader.rs @@ -1,5 +1,3 @@ -use std::any::TypeId; - use crate::Font; use bevy_asset::{io::Reader, AssetLoader, AsyncReadExt, LoadContext}; use thiserror::Error; @@ -39,12 +37,4 @@ impl AssetLoader for FontLoader { fn extensions(&self) -> &[&str] { &["ttf", "otf"] } - - fn label_type_name(&self, _label_type: &str) -> Option<&'static str> { - None - } - - fn label_type_id(&self, _label_type: &str) -> Option { - None - } } From f7d099902aea16a299b8181184becba38afe8506 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9l=C3=A8ne=20Amanita?= Date: Thu, 9 Nov 2023 11:59:23 +0000 Subject: [PATCH 7/7] Remove unnecessary implementation for CoolText unit test --- crates/bevy_asset/src/lib.rs | 10 +--------- 1 file changed, 1 insertion(+), 9 deletions(-) diff --git a/crates/bevy_asset/src/lib.rs b/crates/bevy_asset/src/lib.rs index 03388736c67a7..9f9cd44c77b0d 100644 --- a/crates/bevy_asset/src/lib.rs +++ b/crates/bevy_asset/src/lib.rs @@ -415,7 +415,7 @@ mod tests { use bevy_utils::BoxedFuture; use futures_lite::AsyncReadExt; use serde::{Deserialize, Serialize}; - use std::{any::TypeId, path::Path}; + use std::path::Path; use thiserror::Error; #[derive(Asset, TypePath, Debug)] @@ -501,14 +501,6 @@ mod tests { fn extensions(&self) -> &[&str] { &["cool.ron"] } - - fn label_type_name(&self, _label_type: &str) -> Option<&'static str> { - Some(std::any::type_name::()) - } - - fn label_type_id(&self, _label_type: &str) -> Option { - Some(TypeId::of::()) - } } fn test_app(dir: Dir) -> (App, GateOpener) {