remove lossy conversions, fix linting and doc tests, add more tests for Path replacement methods
This commit is contained in:
parent
ec47b4cdcd
commit
b1733fdbfa
@ -3,7 +3,7 @@ use crate::io::{
|
|||||||
memory::Dir,
|
memory::Dir,
|
||||||
AssetSourceEvent, AssetWatcher,
|
AssetSourceEvent, AssetWatcher,
|
||||||
};
|
};
|
||||||
use alloc::{boxed::Box, sync::Arc, vec::Vec};
|
use alloc::{boxed::Box, string::ToString, sync::Arc, vec::Vec};
|
||||||
use bevy_platform::collections::HashMap;
|
use bevy_platform::collections::HashMap;
|
||||||
use core::time::Duration;
|
use core::time::Duration;
|
||||||
use notify_debouncer_full::{notify::RecommendedWatcher, Debouncer, RecommendedCache};
|
use notify_debouncer_full::{notify::RecommendedWatcher, Debouncer, RecommendedCache};
|
||||||
@ -40,7 +40,9 @@ impl EmbeddedWatcher {
|
|||||||
last_event: None,
|
last_event: None,
|
||||||
};
|
};
|
||||||
let watcher = new_asset_event_debouncer(
|
let watcher = new_asset_event_debouncer(
|
||||||
root.to_string_lossy().to_string(),
|
root.to_str()
|
||||||
|
.expect("non unicode characters found in path")
|
||||||
|
.to_string(),
|
||||||
debounce_wait_time,
|
debounce_wait_time,
|
||||||
handler,
|
handler,
|
||||||
)
|
)
|
||||||
|
@ -545,7 +545,9 @@ impl AssetSource {
|
|||||||
if path.exists() {
|
if path.exists() {
|
||||||
Some(Box::new(
|
Some(Box::new(
|
||||||
super::file::FileWatcher::new(
|
super::file::FileWatcher::new(
|
||||||
path.to_string_lossy().to_string(),
|
path.to_str()
|
||||||
|
.expect("non unicode characters found in path")
|
||||||
|
.to_string(),
|
||||||
sender,
|
sender,
|
||||||
file_debounce_wait_time,
|
file_debounce_wait_time,
|
||||||
)
|
)
|
||||||
|
@ -638,7 +638,11 @@ impl<'a> From<&'a Path> for AssetPath<'a> {
|
|||||||
fn from(path: &'a Path) -> Self {
|
fn from(path: &'a Path) -> Self {
|
||||||
Self {
|
Self {
|
||||||
source: AssetSourceId::Default,
|
source: AssetSourceId::Default,
|
||||||
path: CowArc::from(path.to_string_lossy().to_string()),
|
path: CowArc::from(
|
||||||
|
path.to_str()
|
||||||
|
.expect("non unicode characters found in file path")
|
||||||
|
.to_string(),
|
||||||
|
),
|
||||||
label: None,
|
label: None,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -649,7 +653,11 @@ impl From<PathBuf> for AssetPath<'static> {
|
|||||||
fn from(path: PathBuf) -> Self {
|
fn from(path: PathBuf) -> Self {
|
||||||
Self {
|
Self {
|
||||||
source: AssetSourceId::Default,
|
source: AssetSourceId::Default,
|
||||||
path: CowArc::from(path.to_string_lossy().to_string()),
|
path: CowArc::from(
|
||||||
|
path.to_str()
|
||||||
|
.expect("non unicode characters found in file path")
|
||||||
|
.to_string(),
|
||||||
|
),
|
||||||
label: None,
|
label: None,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -1078,4 +1086,24 @@ mod tests {
|
|||||||
assert_eq!(AssetPath::from("a/b/"), AssetPath::from("a/b"));
|
assert_eq!(AssetPath::from("a/b/"), AssetPath::from("a/b"));
|
||||||
assert_eq!(AssetPath::from("a/b/#c"), AssetPath::from("a/b#c"));
|
assert_eq!(AssetPath::from("a/b/#c"), AssetPath::from("a/b#c"));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test_path_components() {
|
||||||
|
use alloc::vec;
|
||||||
|
use alloc::vec::Vec;
|
||||||
|
|
||||||
|
assert_eq!(
|
||||||
|
AssetPath::from("a/b/c")
|
||||||
|
.path_components()
|
||||||
|
.collect::<Vec<_>>(),
|
||||||
|
vec!["a", "b", "c"]
|
||||||
|
);
|
||||||
|
|
||||||
|
assert_eq!(
|
||||||
|
AssetPath::from("a/b/c/../d")
|
||||||
|
.path_components()
|
||||||
|
.collect::<Vec<_>>(),
|
||||||
|
vec!["a", "b", "c", "..", "d"]
|
||||||
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user