From 5f2371da2e3bea711fb8ea796fe6fee0999cd2b7 Mon Sep 17 00:00:00 2001 From: Andreas Rammhold Date: Tue, 21 Apr 2020 00:17:28 +0200 Subject: [PATCH] fix(list_sync): make sure the public interface allows using the Item type Before this change the public interface wouldn't allow downstream users to use the actual items since it wasn't communicated on the function signature. Previously a user would run into erorrs like this: > no field `key` on type `::Item` --- src/ls.rs | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/src/ls.rs b/src/ls.rs index 90670da..acfe27e 100644 --- a/src/ls.rs +++ b/src/ls.rs @@ -1,9 +1,29 @@ //! Functions for iterating over the cache. +use anyhow::Result; use std::path::Path; use crate::index; /// Returns a synchronous iterator that lists all cache index entries. -pub fn list_sync>(cache: P) -> impl Iterator { +pub fn list_sync>(cache: P) -> impl Iterator> { index::ls(cache.as_ref()) } + +#[cfg(test)] +mod tests { + use super::*; + use tempfile; + + #[test] + fn test_list_sync() { + // check that the public interface to list elements can actually use the + // Iterator::Item + let tmp = tempfile::tempdir().unwrap(); + let dir = tmp.path().to_owned(); + + assert!(list_sync(dir) + .map(|x| Ok(x?.key)) + .collect::>>() + .is_err()) + } +}