From b0704f50a40235cff3a5ae989f82587990dcb4c7 Mon Sep 17 00:00:00 2001 From: "flyingscorpio@clevo" Date: Tue, 10 Jan 2023 20:51:41 +0100 Subject: [PATCH] Remove 'allow unused' macro and handle the warnings therefrom --- src/api_client.rs | 3 --- src/database.rs | 2 +- src/database/crud.rs | 3 +-- src/ear.rs | 7 +++++-- src/lib.rs | 6 +----- 5 files changed, 8 insertions(+), 13 deletions(-) diff --git a/src/api_client.rs b/src/api_client.rs index f21a3b1..137776c 100644 --- a/src/api_client.rs +++ b/src/api_client.rs @@ -1,9 +1,6 @@ //! Holds the elements pertaining to ApiClient, a REST API client. use std::fmt::Display; -use std::fs::read_to_string; -use std::io; -use std::process; use reqwest::Url; use serde_json::Value; diff --git a/src/database.rs b/src/database.rs index 6a6c769..87b72e1 100644 --- a/src/database.rs +++ b/src/database.rs @@ -8,7 +8,7 @@ mod errors; use diesel::prelude::*; use crate::ear::Request; -use crate::models::{Favorite, History, InsertFavorite, InsertHistory, InsertTitle, Title}; +use crate::models::{History, InsertFavorite, InsertHistory, InsertTitle, Title}; use crate::schema::title; use crate::schema::title::dsl::*; pub use errors::DatabaseError; diff --git a/src/database/crud.rs b/src/database/crud.rs index 0094e01..f720512 100644 --- a/src/database/crud.rs +++ b/src/database/crud.rs @@ -1,6 +1,6 @@ //! CRUD operations for the database. -use std::{env, option}; +use std::env; use diesel::pg::PgConnection; use diesel::prelude::*; @@ -10,7 +10,6 @@ use crate::models::{Favorite, History, InsertFavorite, InsertHistory, InsertTitl use crate::schema::favorite; use crate::schema::favorite::dsl::*; use crate::schema::history; -use crate::schema::history::dsl::*; use crate::schema::title; use crate::schema::title::dsl::*; diff --git a/src/ear.rs b/src/ear.rs index dc53f93..6ef6c54 100644 --- a/src/ear.rs +++ b/src/ear.rs @@ -127,8 +127,11 @@ fn parse_uri(full_request: &str) -> Result { } /// Handles a given well formed request -fn handle_request(request: Request, mut sender: Mouth) { - database::save_request_to_history(&request); +fn handle_request(request: Request, sender: Mouth) { + database::save_request_to_history(&request).unwrap_or_else(|err| { + eprintln!("{err}"); + return; + }); match request.method { HttpMethod::Get => handle_get_request(request, sender), diff --git a/src/lib.rs b/src/lib.rs index ee8852d..5269cce 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1,12 +1,9 @@ //! Hephaistos is a web application serving an API. -#![allow(unused)] use std::error::Error; use std::io::Write; use std::{io, process}; -use serde_json::Value; - mod api_client; mod database; mod ear; @@ -17,14 +14,13 @@ mod schema; use api_client::ApiClient; use ear::Ear; use models::InsertTitle; -use mouth::Mouth; /// Entry point of the library, propagates errors to `main`. pub fn run() -> Result<(), Box> { // Start off by populating the local database with all Mirabel titles // Make an API call to Mirabel to fetch all titles print!("Updating the local database... "); - io::stdout().flush(); + io::stdout().flush().expect("wasn't able to flush stdout"); let api_client = ApiClient::new(); let all_titles = api_client.get_titles().unwrap_or_else(|err| { eprintln!("{err}");