1 //! Module for directory iteration. See [`UefiDirectoryIter`].
2 
3 use super::*;
4 use crate::{cstr16, CStr16, Result};
5 use alloc::boxed::Box;
6 
7 /// Common skip dirs in UEFI/FAT-style file systems.
8 pub const COMMON_SKIP_DIRS: &[&CStr16] = &[cstr16!("."), cstr16!("..")];
9 
10 /// Iterates over the entries of an UEFI directory. It returns boxed values of
11 /// type [`UefiFileInfo`].
12 ///
13 /// Note that on UEFI/FAT-style file systems, the root dir usually doesn't
14 /// return the entries `.` and `..`, whereas sub directories do.
15 #[derive(Debug)]
16 pub struct UefiDirectoryIter(UefiDirectoryHandle);
17 
18 impl UefiDirectoryIter {
19     /// Constructor.
20     #[must_use]
new(handle: UefiDirectoryHandle) -> Self21     pub const fn new(handle: UefiDirectoryHandle) -> Self {
22         Self(handle)
23     }
24 }
25 
26 impl Iterator for UefiDirectoryIter {
27     type Item = Result<Box<UefiFileInfo>, ()>;
28 
next(&mut self) -> Option<Self::Item>29     fn next(&mut self) -> Option<Self::Item> {
30         let e = self.0.read_entry_boxed();
31         match e {
32             // no more entries
33             Ok(None) => None,
34             Ok(Some(e)) => Some(Ok(e)),
35             Err(e) => Some(Err(e)),
36         }
37     }
38 }
39