From 2a48d7c3c8c17db738099176ec1764ced4150069 Mon Sep 17 00:00:00 2001 From: lielfr Date: Sun, 8 Jun 2025 23:43:50 +0300 Subject: [PATCH] add file_name method --- crates/bevy_asset/src/path.rs | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/crates/bevy_asset/src/path.rs b/crates/bevy_asset/src/path.rs index a43bf29eb6..640aad2ab7 100644 --- a/crates/bevy_asset/src/path.rs +++ b/crates/bevy_asset/src/path.rs @@ -507,12 +507,18 @@ impl<'a> AssetPath<'a> { } } + /// Returns the file name + /// Ex: Returns `"a.json"` for `"a/b/c/a.json"` + pub fn file_name(&self) -> Option { + self.path().file_name()?.to_str().map(String::from) + } + /// Returns the full extension (including multiple '.' values). /// Ex: Returns `"config.ron"` for `"my_asset.config.ron"` /// /// Also strips out anything following a `?` to handle query parameters in URIs pub fn get_full_extension(&self) -> Option { - let file_name = self.path().file_name()?.to_str()?; + let file_name = self.file_name()?; let index = file_name.find('.')?; let mut extension = file_name[index + 1..].to_owned();