Skip to content

Commit ccc5404

Browse files
nicholasbishopGabrielMajeri
authored andcommitted
Add convenience methods for converting a FileHandle
Add `FileHandle::into_directory` and `FileHandle::into_regular_file`. These can be more convenient than `FileHandle::into_type` when you know what type of file you expect.
1 parent 9e44ca2 commit ccc5404

File tree

2 files changed

+24
-0
lines changed

2 files changed

+24
-0
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@
22

33
## uefi - [Unreleased]
44

5+
### Added
6+
7+
- Added `FileHandle::into_directory` and `FileHandle::into_regular_file`.
8+
59
## uefi-macros - [Unreleased]
610

711
## uefi-services - [Unreleased]

src/proto/media/file/mod.rs

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -238,6 +238,26 @@ impl FileHandle {
238238
s => Err(s.into()),
239239
}
240240
}
241+
242+
/// If the handle represents a directory, convert it into a
243+
/// [`Directory`]. Otherwise returns `None`.
244+
pub fn into_directory(self) -> Option<Directory> {
245+
if let Ok(FileType::Dir(dir)) = self.into_type() {
246+
Some(dir)
247+
} else {
248+
None
249+
}
250+
}
251+
252+
/// If the handle represents a regular file, convert it into a
253+
/// [`RegularFile`]. Otherwise returns `None`.
254+
pub fn into_regular_file(self) -> Option<RegularFile> {
255+
if let Ok(FileType::Regular(regular)) = self.into_type() {
256+
Some(regular)
257+
} else {
258+
None
259+
}
260+
}
241261
}
242262

243263
impl File for FileHandle {

0 commit comments

Comments
 (0)