cacache_sync/ls.rs
1//! Functions for iterating over the cache.
2use std::path::Path;
3
4use crate::errors::Result;
5use crate::index;
6
7/// Returns a synchronous iterator that lists all cache index entries.
8pub fn list<P: AsRef<Path>>(cache: P) -> impl Iterator<Item = Result<index::Metadata>> {
9 index::ls(cache.as_ref())
10}
11
12#[cfg(test)]
13mod tests {
14 use super::*;
15
16 #[test]
17 fn test_list() {
18 // check that the public interface to list elements can actually use the
19 // Iterator::Item
20 let tmp = tempfile::tempdir().unwrap();
21 let dir = tmp.path().to_owned();
22
23 assert!(list(dir)
24 .map(|x| Ok(x?.key))
25 .collect::<Result<Vec<_>>>()
26 .is_err())
27 }
28}