feat: simplify return type of catalog.list method

This commit is contained in:
2026-02-27 10:44:28 +01:00
parent cdf5ead07d
commit 68c6ca4e9f
6 changed files with 4 additions and 9 deletions

View File

@@ -134,7 +134,6 @@ fn main() {
.list::<Component>()
.unwrap()
.into_iter()
.map(|c| c.unwrap())
.collect();
// Print the loaded components
println!(

View File

@@ -145,7 +145,6 @@ fn main() -> Result<(), FailedTo> {
.list()
.unwrap()
.into_iter()
.map(|p| p.unwrap())
.collect();
println!("✅ Loaded {} laptop(s) using filter.", laptops.len());
@@ -173,7 +172,6 @@ fn main() -> Result<(), FailedTo> {
.list()
.unwrap()
.into_iter()
.map(|p| p.unwrap())
.collect();
println!(
@@ -205,7 +203,6 @@ fn main() -> Result<(), FailedTo> {
.list()
.unwrap()
.into_iter()
.map(|p| p.unwrap())
.collect();
println!("✅ Loaded {} total products.", all_products.len());

View File

View File

@@ -20,7 +20,7 @@ impl Catalog {
///
/// Returns `Err(FailedTo::LockCatalog)` if the catalog's internal mutex
/// could not be locked.
pub fn list<T>(&self) -> Result<Vec<Result<T, FailedTo>>, FailedTo>
pub fn list<T>(&self) -> Result<Vec<T>, FailedTo>
where
T: EAV,
{
@@ -28,7 +28,7 @@ impl Catalog {
Ok(items
.values()
.filter(move |item| item.class == T::class())
.map(|item| T::try_from(item.clone()).map_err(|_| FailedTo::ConvertEntity))
.filter_map(|item| T::try_from(item.clone()).ok())
.collect())
})
}

View File

@@ -74,7 +74,6 @@ mod tests {
.list::<Item>()
.unwrap()
.into_iter()
.map(|item| item.unwrap())
.collect();
// Sort by ID to ensure consistent order for comparison
let mut expected_items = items_to_insert;

View File

@@ -27,8 +27,8 @@ mod tests {
let _ = catalog.upsert(item2.clone());
let results = catalog.list::<Item>().unwrap();
assert_eq!(results.len(), 2);
assert!(results.contains(&Ok(item1)));
assert!(results.contains(&Ok(item2)));
assert!(results.contains(&item1));
assert!(results.contains(&item2));
}
#[test]
fn list_by_class_should_return_empty_iterator_if_no_match() {