fix lints

This commit is contained in:
lielfr 2025-05-09 03:42:54 +03:00
parent 48e06917de
commit c205b0046e

View File

@ -6,6 +6,7 @@ use alloc::{
}; };
use atomicow::CowArc; use atomicow::CowArc;
use bevy_reflect::{Reflect, ReflectDeserialize, ReflectSerialize}; use bevy_reflect::{Reflect, ReflectDeserialize, ReflectSerialize};
use core::hash::Hasher;
use core::{ use core::{
fmt::{Debug, Display}, fmt::{Debug, Display},
hash::Hash, hash::Hash,
@ -51,7 +52,7 @@ use thiserror::Error;
/// This means that the common case of `asset_server.load("my_scene.scn")` when it creates and /// This means that the common case of `asset_server.load("my_scene.scn")` when it creates and
/// clones internal owned [`AssetPaths`](AssetPath). /// clones internal owned [`AssetPaths`](AssetPath).
/// This also means that you should use [`AssetPath::parse`] in cases where `&str` is the explicit type. /// This also means that you should use [`AssetPath::parse`] in cases where `&str` is the explicit type.
#[derive(Eq, Hash, Clone, Default, Reflect)] #[derive(Eq, Clone, Default, Reflect)]
#[reflect(opaque)] #[reflect(opaque)]
#[reflect(Debug, PartialEq, Hash, Clone, Serialize, Deserialize)] #[reflect(Debug, PartialEq, Hash, Clone, Serialize, Deserialize)]
pub struct AssetPath<'a> { pub struct AssetPath<'a> {
@ -60,7 +61,7 @@ pub struct AssetPath<'a> {
label: Option<CowArc<'a, str>>, label: Option<CowArc<'a, str>>,
} }
/// PartialEq needs to be derived manually for backwards compatibility. /// `PartialEq` needs to be derived manually for backwards compatibility.
/// As `path` used to be `std::path::Path`, equality was tricky with a trailing slash. /// As `path` used to be `std::path::Path`, equality was tricky with a trailing slash.
/// For example, "martin/stephan#dave" should be equal to "martin/stephan/#dave". /// For example, "martin/stephan#dave" should be equal to "martin/stephan/#dave".
impl<'a> PartialEq for AssetPath<'a> { impl<'a> PartialEq for AssetPath<'a> {
@ -79,6 +80,19 @@ impl<'a> PartialEq for AssetPath<'a> {
} }
} }
impl<'a> Hash for AssetPath<'a> {
fn hash<H: Hasher>(&self, state: &mut H) {
let path = if self.path.ends_with('/') {
&self.path[..self.path.len() - 1]
} else {
&self.path
};
self.source.hash(state);
state.write(path.as_bytes());
self.label.hash(state);
}
}
impl<'a> Debug for AssetPath<'a> { impl<'a> Debug for AssetPath<'a> {
fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
Display::fmt(self, f) Display::fmt(self, f)
@ -363,7 +377,7 @@ impl<'a> AssetPath<'a> {
if self.path.as_ref() == "/" || self.path.starts_with('#') || self.path.is_empty() { if self.path.as_ref() == "/" || self.path.starts_with('#') || self.path.is_empty() {
return None; return None;
} }
let mut path: Vec<_> = self.path_components().map(|s| s.to_string()).collect(); let mut path: Vec<_> = self.path_components().map(ToString::to_string).collect();
path.pop(); path.pop();
let path = path.join("/"); let path = path.join("/");
Some(AssetPath { Some(AssetPath {