utils/pathbuf.rs
1//! Various helper methods for working with Rust's [`PathBuf`].
2
3use std::path::Path;
4
5/// Retrieves the file name from the given [`PathBuf`].
6///
7/// This method is lossy in case of invalid UTF-8 characters, see [`OsStr::to_string_lossy`]
8#[inline]
9#[must_use]
10pub fn file_name(path: &Path) -> Option<String> {
11 Some(path.file_name()?.to_string_lossy().to_string())
12}