clippy
This commit is contained in:
@@ -14,14 +14,14 @@ impl Inventory {
|
||||
div id="pkglist-item-manager" {
|
||||
div ."p-8" ."grid" ."grid-cols-4" ."gap-3" {
|
||||
div ."col-span-2" {
|
||||
({<InventoryCategoryList as Into<Markup>>::into(InventoryCategoryList::build(&categories).await?)})
|
||||
({<InventoryCategoryList as Into<Markup>>::into(InventoryCategoryList::build(&categories))})
|
||||
}
|
||||
div ."col-span-2" {
|
||||
h1 ."text-2xl" ."mb-5" ."text-center" { "Items" }
|
||||
@if state.active_category_id.is_some() {
|
||||
({<InventoryItemList as Into<Markup>>::into(InventoryItemList::build(categories.iter().find(|category| category.active).unwrap().items()).await?)})
|
||||
({<InventoryItemList as Into<Markup>>::into(InventoryItemList::build(categories.iter().find(|category| category.active).unwrap().items()))})
|
||||
}
|
||||
({<InventoryNewItemForm as Into<Markup>>::into(InventoryNewItemForm::build(&state, &categories).await?)})
|
||||
({<InventoryNewItemForm as Into<Markup>>::into(InventoryNewItemForm::build(&state, &categories))})
|
||||
|
||||
}
|
||||
}
|
||||
@@ -43,10 +43,10 @@ pub struct InventoryCategoryList {
|
||||
}
|
||||
|
||||
impl InventoryCategoryList {
|
||||
pub async fn build(categories: &Vec<Category>) -> Result<Self, Error> {
|
||||
pub fn build(categories: &Vec<Category>) -> 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::<u32>().to_string())
|
||||
(categories.iter().map(Category::total_weight).sum::<u32>().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<Item>) -> Result<Self, Error> {
|
||||
pub fn build(items: &Vec<Item>) -> 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<Category>) -> Result<Self, Error> {
|
||||
pub fn build(state: &ClientState, categories: &Vec<Category>) -> Self {
|
||||
let doc = html!(
|
||||
|
||||
form
|
||||
@@ -335,7 +335,7 @@ impl InventoryNewItemForm {
|
||||
}
|
||||
);
|
||||
|
||||
Ok(Self { doc })
|
||||
Self { doc }
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -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 {
|
||||
|
||||
@@ -103,7 +103,7 @@ async fn main() -> Result<(), sqlx::Error> {
|
||||
async fn root() -> (StatusCode, Html<String>) {
|
||||
(
|
||||
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::<Vec<Result<Category, models::Error>>>()
|
||||
.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<String>), (StatusCode, Html<String>)> {
|
||||
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::<Vec<Result<Trip, models::Error>>>()
|
||||
.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()),
|
||||
))
|
||||
}
|
||||
|
||||
|
||||
@@ -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::<Vec<Result<Item, Error>>>()
|
||||
.await?
|
||||
.into_iter()
|
||||
|
||||
Reference in New Issue
Block a user