diff --git a/rust/src/components/inventory.rs b/rust/src/components/inventory.rs index f5083f6..5e9e529 100644 --- a/rust/src/components/inventory.rs +++ b/rust/src/components/inventory.rs @@ -14,14 +14,14 @@ impl Inventory { div id="pkglist-item-manager" { div ."p-8" ."grid" ."grid-cols-4" ."gap-3" { div ."col-span-2" { - ({>::into(InventoryCategoryList::build(&categories).await?)}) + ({>::into(InventoryCategoryList::build(&categories))}) } div ."col-span-2" { h1 ."text-2xl" ."mb-5" ."text-center" { "Items" } @if state.active_category_id.is_some() { - ({>::into(InventoryItemList::build(categories.iter().find(|category| category.active).unwrap().items()).await?)}) + ({>::into(InventoryItemList::build(categories.iter().find(|category| category.active).unwrap().items()))}) } - ({>::into(InventoryNewItemForm::build(&state, &categories).await?)}) + ({>::into(InventoryNewItemForm::build(&state, &categories))}) } } @@ -43,10 +43,10 @@ pub struct InventoryCategoryList { } impl InventoryCategoryList { - pub async fn build(categories: &Vec) -> Result { + pub fn build(categories: &Vec) -> Self { let biggest_category_weight: u32 = categories .iter() - .map(|category| category.total_weight()) + .map(Category::total_weight) .max() .unwrap_or(1); @@ -116,8 +116,8 @@ impl InventoryCategoryList { format!( "width: {width}%;position:absolute;left:0;bottom:0;right:0;", width=( - category.total_weight() as f32 - / biggest_category_weight as f32 + f64::from(category.total_weight()) + / f64::from(biggest_category_weight) * 100.0 ) ) @@ -131,7 +131,7 @@ impl InventoryCategoryList { } td ."border" ."p-0" ."m-0" { p ."p-2" ."m-2" { - (categories.iter().map(|category| category.total_weight()).sum::().to_string()) + (categories.iter().map(Category::total_weight).sum::().to_string()) } } } @@ -140,7 +140,7 @@ impl InventoryCategoryList { } ); - Ok(Self { doc }) + Self { doc } } } @@ -155,7 +155,7 @@ pub struct InventoryItemList { } impl InventoryItemList { - pub async fn build(items: &Vec) -> Result { + pub fn build(items: &Vec) -> Self { let biggest_item_weight: u32 = items.iter().map(|item| item.weight).max().unwrap_or(1); let doc = html!( div #items { @@ -196,7 +196,7 @@ impl InventoryItemList { position:absolute; left:0; bottom:0; - right:0;", width=(item.weight as f32 / biggest_item_weight as f32 * 100.0))) {} + right:0;", width=(f64::from(item.weight) / f64::from(biggest_item_weight) * 100.0))) {} } td ."border" @@ -222,7 +222,7 @@ impl InventoryItemList { } ); - Ok(Self { doc }) + Self { doc } } } @@ -237,7 +237,7 @@ pub struct InventoryNewItemForm { } impl InventoryNewItemForm { - pub async fn build(state: &ClientState, categories: &Vec) -> Result { + pub fn build(state: &ClientState, categories: &Vec) -> Self { let doc = html!( form @@ -335,7 +335,7 @@ impl InventoryNewItemForm { } ); - Ok(Self { doc }) + Self { doc } } } diff --git a/rust/src/components/mod.rs b/rust/src/components/mod.rs index c5e4537..122a035 100644 --- a/rust/src/components/mod.rs +++ b/rust/src/components/mod.rs @@ -19,7 +19,7 @@ pub enum TopLevelPage { } impl Root { - pub fn build(body: Markup, active_page: TopLevelPage) -> Self { + pub fn build(body: Markup, active_page: &TopLevelPage) -> Self { let doc = html!( (DOCTYPE) html { diff --git a/rust/src/main.rs b/rust/src/main.rs index 424b715..127d448 100644 --- a/rust/src/main.rs +++ b/rust/src/main.rs @@ -103,7 +103,7 @@ async fn main() -> Result<(), sqlx::Error> { async fn root() -> (StatusCode, Html) { ( StatusCode::OK, - Html::from(Root::build(Home::build().into(), TopLevelPage::None).into_string()), + Html::from(Root::build(Home::build().into(), &TopLevelPage::None).into_string()), ) } @@ -133,7 +133,7 @@ async fn inventory( let mut categories = query("SELECT id,name,description FROM inventoryitemcategories") .fetch(&state.database_pool) - .map_ok(|row| row.try_into()) + .map_ok(std::convert::TryInto::try_into) .try_collect::>>() .await // we have two error handling lines here. these are distinct errors @@ -166,7 +166,7 @@ async fn inventory( .await .map_err(|e| (StatusCode::INTERNAL_SERVER_ERROR, Html::from(e.to_string())))? .into(), - TopLevelPage::Inventory, + &TopLevelPage::Inventory, ) .into_string(), ), @@ -178,7 +178,7 @@ async fn trips( ) -> Result<(StatusCode, Html), (StatusCode, Html)> { let trips = query("SELECT * FROM trips") .fetch(&state.database_pool) - .map_ok(|row| row.try_into()) + .map_ok(std::convert::TryInto::try_into) .try_collect::>>() .await // we have two error handling lines here. these are distinct errors @@ -192,7 +192,7 @@ async fn trips( Ok(( StatusCode::OK, - Html::from(Root::build(TripList::build(trips).into(), TopLevelPage::Trips).into_string()), + Html::from(Root::build(TripList::build(trips).into(), &TopLevelPage::Trips).into_string()), )) } diff --git a/rust/src/models.rs b/rust/src/models.rs index f91eba3..7a94434 100644 --- a/rust/src/models.rs +++ b/rust/src/models.rs @@ -17,10 +17,10 @@ impl fmt::Display for Error { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { match self { Self::SqlError { description } => { - write!(f, "SQL error: {}", description) + write!(f, "SQL error: {description}") } Self::UuidError { description } => { - write!(f, "UUID error: {}", description) + write!(f, "UUID error: {description}") } } } @@ -29,7 +29,7 @@ impl fmt::Display for Error { impl fmt::Debug for Error { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { // defer to Display - write!(f, "SQL error: {}", self) + write!(f, "SQL error: {self}") } } @@ -129,7 +129,7 @@ impl<'a> Category { id = self.id )) .fetch(&pool) - .map_ok(|row| row.try_into()) + .map_ok(std::convert::TryInto::try_into) .try_collect::>>() .await? .into_iter()