diff --git a/crates/bevy_asset/src/path.rs b/crates/bevy_asset/src/path.rs index 1285b1863a7cba..574bb06b570d8a 100644 --- a/crates/bevy_asset/src/path.rs +++ b/crates/bevy_asset/src/path.rs @@ -121,37 +121,37 @@ impl<'a> AssetPath<'a> { } } - /// Resolves a relative asset path. The result will be an `AssetPath` which is resolved relative - /// to this path. + /// Resolves a possibly-relative path string relative to a base path, producing an `AssetPath`. /// - /// If the relative path begins with `#`, then it is considered an asset label, in which case + /// If the path argument begins with `#`, then it is considered an asset label, in which case /// the result is the base path with the label portion replaced. /// - /// If the relative path starts with "./" or "../", then the result is combined with the base - /// path and canonicalized. The rules are the same as for URIs, which means that the relative - /// path is resolved relative to the *directory* of the base path, so a base path of - /// `"x/y/z#foo"` combined with a relative path of `"./a#bar"` yields `"x/y/a#bar"`. + /// If the path argument starts with "./" or "../", then the result the concatenation of + /// the base path and the path argument, which is then canonicalized. The rules are the same as + /// for URIs, which means that the path argument is resolved relative to the *directory* of the + /// base path, so a base path of `"x/y/z#foo"` combined with a relative path of `"./a#bar"` + /// yields `"x/y/a#bar"`. /// - /// If neither of the above are true, then the relative path is considered a 'full' path, - /// and the result is simply a canonicalized version of the relative path string, converted + /// If neither of the above are true, then the path argument is considered a 'full' path, + /// and the result is simply a canonicalized version of the argument string, converted /// into an `AssetPath`. Note that a 'full' asset path is still relative to the asset root /// directory, and not necessarily an absolute filesystem path. /// - /// Note that "./" and "../" elements are only canonicalized in the relative path, any such + /// Note that "./" and "../" elements are only canonicalized in the path argument, any such /// elements in the base path are left as-is. /// /// # Panics /// - /// This method will panic if the relative path has more 'parent' elements ("../") than + /// This method will panic if the path argument has more 'parent' elements ("../") than /// are available in the base path. - pub fn resolve(&'a self, relative_path: &'a str) -> AssetPath<'a> { - if let Some(label) = relative_path.strip_prefix('#') { + pub fn resolve(&'a self, path: &'a str) -> AssetPath<'a> { + if let Some(label) = path.strip_prefix('#') { // It's a label only AssetPath::new_ref(&self.path, Some(label)) } else { - let (rpath, rlabel) = match relative_path.split_once('#') { + let (rpath, rlabel) = match path.split_once('#') { Some((path, label)) => (path, Some(label.to_string())), - None => (relative_path, None), + None => (path, None), }; let mut fpath = PathBuf::from(self.path()); if !fpath.pop() {