From 68c6ca4e9f92ad15ed6a64a64dd8170c5a92df81 Mon Sep 17 00:00:00 2001 From: davidemazzocchi Date: Fri, 27 Feb 2026 10:44:28 +0100 Subject: [PATCH] feat: simplify return type of catalog.list method --- 01.workspace/heave/examples/using_filters.rs | 1 - 01.workspace/heave/examples/working_with_many_types.rs | 3 --- 01.workspace/heave/src/full_diff.txt | 0 01.workspace/heave/src/imp/catalog_list.rs | 4 ++-- 01.workspace/heave/src/tst/catalog_integration.rs | 1 - 01.workspace/heave/src/tst/catalog_list_by_class.rs | 4 ++-- 6 files changed, 4 insertions(+), 9 deletions(-) create mode 100644 01.workspace/heave/src/full_diff.txt diff --git a/01.workspace/heave/examples/using_filters.rs b/01.workspace/heave/examples/using_filters.rs index b7481e3..28c0f93 100644 --- a/01.workspace/heave/examples/using_filters.rs +++ b/01.workspace/heave/examples/using_filters.rs @@ -134,7 +134,6 @@ fn main() { .list::() .unwrap() .into_iter() - .map(|c| c.unwrap()) .collect(); // Print the loaded components println!( diff --git a/01.workspace/heave/examples/working_with_many_types.rs b/01.workspace/heave/examples/working_with_many_types.rs index fa47a5a..b34f1ec 100644 --- a/01.workspace/heave/examples/working_with_many_types.rs +++ b/01.workspace/heave/examples/working_with_many_types.rs @@ -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()); diff --git a/01.workspace/heave/src/full_diff.txt b/01.workspace/heave/src/full_diff.txt new file mode 100644 index 0000000..e69de29 diff --git a/01.workspace/heave/src/imp/catalog_list.rs b/01.workspace/heave/src/imp/catalog_list.rs index 2ee98ad..9004b4d 100644 --- a/01.workspace/heave/src/imp/catalog_list.rs +++ b/01.workspace/heave/src/imp/catalog_list.rs @@ -20,7 +20,7 @@ impl Catalog { /// /// Returns `Err(FailedTo::LockCatalog)` if the catalog's internal mutex /// could not be locked. - pub fn list(&self) -> Result>, FailedTo> + pub fn list(&self) -> Result, 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()) }) } diff --git a/01.workspace/heave/src/tst/catalog_integration.rs b/01.workspace/heave/src/tst/catalog_integration.rs index d1c7a88..9c80e60 100644 --- a/01.workspace/heave/src/tst/catalog_integration.rs +++ b/01.workspace/heave/src/tst/catalog_integration.rs @@ -74,7 +74,6 @@ mod tests { .list::() .unwrap() .into_iter() - .map(|item| item.unwrap()) .collect(); // Sort by ID to ensure consistent order for comparison let mut expected_items = items_to_insert; diff --git a/01.workspace/heave/src/tst/catalog_list_by_class.rs b/01.workspace/heave/src/tst/catalog_list_by_class.rs index 274b07a..a759b6d 100644 --- a/01.workspace/heave/src/tst/catalog_list_by_class.rs +++ b/01.workspace/heave/src/tst/catalog_list_by_class.rs @@ -27,8 +27,8 @@ mod tests { let _ = catalog.upsert(item2.clone()); let results = catalog.list::().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() {