chore: run cargo format on the code base
This commit is contained in:
@@ -141,11 +141,7 @@ fn main() -> Result<(), FailedTo> {
|
||||
|
||||
laptop_catalog.load_by_filter(&laptop_filter)?;
|
||||
|
||||
let laptops: Vec<Product> = laptop_catalog
|
||||
.list()
|
||||
.unwrap()
|
||||
.into_iter()
|
||||
.collect();
|
||||
let laptops: Vec<Product> = laptop_catalog.list().unwrap().into_iter().collect();
|
||||
|
||||
println!("✅ Loaded {} laptop(s) using filter.", laptops.len());
|
||||
assert_eq!(laptops.len(), 2);
|
||||
@@ -168,11 +164,7 @@ fn main() -> Result<(), FailedTo> {
|
||||
|
||||
expensive_catalog.load_by_filter(&expensive_filter)?;
|
||||
|
||||
let expensive_products: Vec<Product> = expensive_catalog
|
||||
.list()
|
||||
.unwrap()
|
||||
.into_iter()
|
||||
.collect();
|
||||
let expensive_products: Vec<Product> = expensive_catalog.list().unwrap().into_iter().collect();
|
||||
|
||||
println!(
|
||||
"✅ Loaded {} product(s) with price > $1000.",
|
||||
@@ -199,11 +191,7 @@ fn main() -> Result<(), FailedTo> {
|
||||
let all_products_filter = Filter::new().with_class(Product::class());
|
||||
all_products_catalog.load_by_filter(&all_products_filter)?;
|
||||
|
||||
let all_products: Vec<Product> = all_products_catalog
|
||||
.list()
|
||||
.unwrap()
|
||||
.into_iter()
|
||||
.collect();
|
||||
let all_products: Vec<Product> = all_products_catalog.list().unwrap().into_iter().collect();
|
||||
|
||||
println!("✅ Loaded {} total products.", all_products.len());
|
||||
assert_eq!(all_products.len(), 4);
|
||||
|
||||
@@ -25,8 +25,7 @@ pub fn run(path: &path::Path) -> result::Result<(), FailedTo> {
|
||||
CREATE INDEX IF NOT EXISTS attribute_id ON attribute (id);
|
||||
CREATE INDEX IF NOT EXISTS attribute_entity_id ON attribute (entity_id);
|
||||
"#;
|
||||
let connection = Connection::open(path)
|
||||
.map_err(sqlite::FailedTo::OpenConnection)?;
|
||||
let connection = Connection::open(path).map_err(sqlite::FailedTo::OpenConnection)?;
|
||||
connection
|
||||
.execute_batch(init_statement)
|
||||
.map_err(sqlite::FailedTo::ExecuteBatch)?;
|
||||
|
||||
@@ -8,8 +8,7 @@ const SELECT_ENTITY_BY_CLASS: &str = r#"
|
||||
|
||||
pub fn run(path: &path::Path, entity_class: &str) -> Result<Vec<Entity>, FailedTo> {
|
||||
let mut entities = Vec::<Entity>::new();
|
||||
let mut connection = Connection::open(path)
|
||||
.map_err(sqlite::FailedTo::OpenConnection)?;
|
||||
let mut connection = Connection::open(path).map_err(sqlite::FailedTo::OpenConnection)?;
|
||||
let mut transaction = connection
|
||||
.transaction()
|
||||
.map_err(sqlite::FailedTo::BeginTransaction)?;
|
||||
|
||||
@@ -3,8 +3,7 @@ use rusqlite::*;
|
||||
|
||||
pub fn run(path: &path::Path, filter: &Filter) -> Result<Vec<Entity>, FailedTo> {
|
||||
let mut entities = Vec::<Entity>::new();
|
||||
let mut connection = Connection::open(path)
|
||||
.map_err(sqlite::FailedTo::OpenConnection)?;
|
||||
let mut connection = Connection::open(path).map_err(sqlite::FailedTo::OpenConnection)?;
|
||||
let mut transaction = connection
|
||||
.transaction()
|
||||
.map_err(sqlite::FailedTo::BeginTransaction)?;
|
||||
|
||||
@@ -7,8 +7,7 @@ const SELECT_ENTITY_BY_ID: &str = r#"
|
||||
"#;
|
||||
|
||||
pub fn run(path: &path::Path, entity_id: &str) -> Result<Option<Entity>, FailedTo> {
|
||||
let mut connection = Connection::open(path)
|
||||
.map_err(sqlite::FailedTo::OpenConnection)?;
|
||||
let mut connection = Connection::open(path).map_err(sqlite::FailedTo::OpenConnection)?;
|
||||
let mut transaction = connection
|
||||
.transaction()
|
||||
.map_err(sqlite::FailedTo::BeginTransaction)?;
|
||||
|
||||
@@ -66,8 +66,7 @@ fn write_entity(entity: &Entity, transaction: &rusqlite::Transaction) -> Result<
|
||||
}
|
||||
|
||||
pub fn run(path: &path::Path, items: &HashMap<String, Entity>) -> result::Result<(), FailedTo> {
|
||||
let mut connection = Connection::open(path)
|
||||
.map_err(sqlite::FailedTo::OpenConnection)?;
|
||||
let mut connection = Connection::open(path).map_err(sqlite::FailedTo::OpenConnection)?;
|
||||
let transaction = connection
|
||||
.transaction()
|
||||
.map_err(sqlite::FailedTo::BeginTransaction)?;
|
||||
|
||||
@@ -30,7 +30,7 @@ impl Catalog {
|
||||
.values()
|
||||
.filter(move |item| item.class == T::class())
|
||||
.filter(move |item| item.subclass.as_deref() == Some(subclass))
|
||||
.filter_map(|item| { T::try_from(item.clone()).ok() })
|
||||
.filter_map(|item| T::try_from(item.clone()).ok())
|
||||
.collect())
|
||||
})
|
||||
}
|
||||
|
||||
@@ -70,11 +70,7 @@ mod tests {
|
||||
// 2. new catalog -> 'load_by_class' -> 'list_by_class'
|
||||
let catalog2 = Catalog::new(db_path);
|
||||
catalog2.load::<Item>().unwrap();
|
||||
let mut loaded_items: Vec<Item> = catalog2
|
||||
.list::<Item>()
|
||||
.unwrap()
|
||||
.into_iter()
|
||||
.collect();
|
||||
let mut loaded_items: Vec<Item> = catalog2.list::<Item>().unwrap().into_iter().collect();
|
||||
// Sort by ID to ensure consistent order for comparison
|
||||
let mut expected_items = items_to_insert;
|
||||
loaded_items.sort_by(|a, b| a.id.cmp(&b.id));
|
||||
|
||||
Reference in New Issue
Block a user