feat: simplify return type of catalog.list_by_subclass method
This commit is contained in:
@@ -24,7 +24,7 @@ impl Catalog {
|
|||||||
///
|
///
|
||||||
/// Returns `Err(FailedTo::LockCatalog)` if the catalog's internal mutex
|
/// Returns `Err(FailedTo::LockCatalog)` if the catalog's internal mutex
|
||||||
/// could not be locked.
|
/// could not be locked.
|
||||||
pub fn list_by_subclass<T>(&self, subclass: &str) -> Result<Vec<Result<T, FailedTo>>, FailedTo>
|
pub fn list_by_subclass<T>(&self, subclass: &str) -> Result<Vec<T>, FailedTo>
|
||||||
where
|
where
|
||||||
T: EAV,
|
T: EAV,
|
||||||
{
|
{
|
||||||
@@ -33,7 +33,7 @@ impl Catalog {
|
|||||||
.values()
|
.values()
|
||||||
.filter(move |item| item.class == T::class())
|
.filter(move |item| item.class == T::class())
|
||||||
.filter(move |item| item.subclass == Some(subclass.to_string()))
|
.filter(move |item| item.subclass == Some(subclass.to_string()))
|
||||||
.map(|item| T::try_from(item.clone()).map_err(|_| FailedTo::ConvertEntity))
|
.filter_map(|item| { T::try_from(item.clone()).ok() })
|
||||||
.collect())
|
.collect())
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -26,7 +26,6 @@ mod tests {
|
|||||||
.list_by_subclass::<Item>("electronics")
|
.list_by_subclass::<Item>("electronics")
|
||||||
.unwrap()
|
.unwrap()
|
||||||
.into_iter()
|
.into_iter()
|
||||||
.map(|item| item.unwrap())
|
|
||||||
.collect();
|
.collect();
|
||||||
assert_eq!(results.len(), 2);
|
assert_eq!(results.len(), 2);
|
||||||
assert!(results.contains(&item1));
|
assert!(results.contains(&item1));
|
||||||
@@ -46,7 +45,6 @@ mod tests {
|
|||||||
.list_by_subclass::<Item>("books")
|
.list_by_subclass::<Item>("books")
|
||||||
.unwrap()
|
.unwrap()
|
||||||
.into_iter()
|
.into_iter()
|
||||||
.map(|item| item.unwrap())
|
|
||||||
.collect();
|
.collect();
|
||||||
assert!(results.is_empty());
|
assert!(results.is_empty());
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user