diff options
author | Till Höppner | 2016-09-15 23:31:11 +0200 |
---|---|---|
committer | GitHub | 2016-09-15 23:31:11 +0200 |
commit | 7bcd1b7d827517cf8df0fdc86a698a171a32f736 (patch) | |
tree | 1f175d26bc73dc2f58492188e19bbdbaa3bc52f7 /lib | |
parent | b08684329bd0601550e3aa6f0926ce1e755668e8 (diff) | |
parent | cae983f2cc93258c69e0f28e149d5da7802bb464 (diff) | |
download | includedir-7bcd1b7d827517cf8df0fdc86a698a171a32f736.tar.gz includedir-7bcd1b7d827517cf8df0fdc86a698a171a32f736.tar.xz includedir-7bcd1b7d827517cf8df0fdc86a698a171a32f736.zip |
Merge pull request #1 from emk/file_names_iter
Allow iteration over available file names
Diffstat (limited to 'lib')
-rw-r--r-- | lib/src/lib.rs | 21 |
1 files changed, 21 insertions, 0 deletions
diff --git a/lib/src/lib.rs b/lib/src/lib.rs index ce1e2ec..57d3610 100644 --- a/lib/src/lib.rs +++ b/lib/src/lib.rs @@ -37,6 +37,12 @@ impl Files { self.files.contains_key(path) } + /// Returns an iterator over all available file names. Does not + /// decompress any compressed data. + pub fn file_names(&self) -> FileNames { + FileNames { iter: self.files.keys() } + } + pub fn get(&self, path: &str) -> io::Result<Cow<'static, [u8]>> { let key = as_key(path); match self.files.get(key.borrow() as &str) { @@ -83,3 +89,18 @@ impl Files { } } } + +/// Iterates over the file names available for `Files` object. +pub struct FileNames<'a> { + /// Our internal iterator. We wrap this in a nice struct so our + /// caller doesn't need to know the details. + iter: phf::map::Keys<'a, &'static str, (Compression, &'static [u8])>, +} + +impl<'a> Iterator for FileNames<'a> { + type Item = &'static str; + + fn next(&mut self) -> Option<Self::Item> { + self.iter.next().map(|s| *s) + } +} |