src/assets.rs: Extract helper method OpenedInput::path()

This commit is contained in:
Martin Nordholts committed 2021-09-27 08:00:58 +02:00
1 parent 9d9b266f54
commit dc8225f682
2 files changed
+17 -13

No files matched your search

+15
View File
@@ -108,6 +108,21 @@ pub(crate) struct OpenedInput<'a> {
pub(crate) description: InputDescription,
}
impl OpenedInput<'_> {
/// Get the path of the file:
/// If this was set by the metadata, that will take priority.
/// If it wasn't, it will use the real file path (if available).
pub(crate) fn path(&self) -> Option<&PathBuf> {
self.metadata
.user_provided_name
.as_ref()
.or_else(|| match self.kind {
OpenedInputKind::OrdinaryFile(ref path) => Some(path),
_ => None,
})
}
}
impl<'a> Input<'a> {
pub fn ordinary_file(path: impl AsRef<Path>) -> Self {
Self::_ordinary_file(path.as_ref())