feat: simplify return type of catalog.list method
This commit is contained in:
@@ -134,7 +134,6 @@ fn main() {
|
||||
.list::<Component>()
|
||||
.unwrap()
|
||||
.into_iter()
|
||||
.map(|c| c.unwrap())
|
||||
.collect();
|
||||
// Print the loaded components
|
||||
println!(
|
||||
|
||||
@@ -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());
|
||||
|
||||
0
01.workspace/heave/src/full_diff.txt
Normal file
0
01.workspace/heave/src/full_diff.txt
Normal 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())
|
||||
})
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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() {
|
||||
|
||||
Reference in New Issue
Block a user