diff --git a/src/core/images.rs b/src/core/images.rs index 3c3da68..d09f98b 100644 --- a/src/core/images.rs +++ b/src/core/images.rs @@ -2,7 +2,7 @@ use crate::{Background, Slide, SlideBuilder, TextAlignment}; use super::{model::Model, service_items::ServiceTrait}; use crisp::types::{Keyword, Value}; -use miette::{miette, IntoDiagnostic, Result}; +use miette::{IntoDiagnostic, Result}; use serde::{Deserialize, Serialize}; use sqlx::{query_as, SqliteConnection}; use std::path::PathBuf; @@ -114,7 +114,7 @@ pub async fn get_image_from_db( database_id: i32, db: &mut SqliteConnection, ) -> Result { - Ok(query_as!(Image, r#"SELECT title as "title!", file_path as "path!", id as "id: i32" from images where id = ?"#, database_id).fetch_one(db).await.into_diagnostic()?) + query_as!(Image, r#"SELECT title as "title!", file_path as "path!", id as "id: i32" from images where id = ?"#, database_id).fetch_one(db).await.into_diagnostic() } #[cfg(test)] diff --git a/src/core/kinds.rs b/src/core/kinds.rs index a14b36e..0dbabdc 100644 --- a/src/core/kinds.rs +++ b/src/core/kinds.rs @@ -6,7 +6,7 @@ use crate::Slide; use super::{ images::Image, - presentations::{PresKind, Presentation}, + presentations::Presentation, songs::Song, videos::Video, }; diff --git a/src/core/model.rs b/src/core/model.rs index 979a3f7..9f7b401 100644 --- a/src/core/model.rs +++ b/src/core/model.rs @@ -1,7 +1,7 @@ use std::mem::replace; -use cosmic::{executor, iced::Executor, Task}; -use miette::{miette, IntoDiagnostic, Result}; +use cosmic::iced::Executor; +use miette::{miette, Result}; use sqlx::{Connection, SqliteConnection}; #[derive(Debug)] diff --git a/src/core/presentations.rs b/src/core/presentations.rs index f902d05..1e390d1 100644 --- a/src/core/presentations.rs +++ b/src/core/presentations.rs @@ -1,5 +1,5 @@ use crisp::types::{Keyword, Value}; -use miette::{miette, IntoDiagnostic, Result}; +use miette::{IntoDiagnostic, Result}; use serde::{Deserialize, Serialize}; use sqlx::{ prelude::FromRow, query, sqlite::SqliteRow, Row, SqliteConnection, @@ -164,7 +164,7 @@ pub async fn get_presentation_from_db( db: &mut SqliteConnection, ) -> Result { let row = query(r#"SELECT id as "id: i32", title, file_path as "path", html from presentations where id = $1"#).bind(database_id).fetch_one(db).await.into_diagnostic()?; - Ok(Presentation::from_row(&row).into_diagnostic()?) + Presentation::from_row(&row).into_diagnostic() } #[cfg(test)] diff --git a/src/core/slide.rs b/src/core/slide.rs index 6729254..3986dd4 100644 --- a/src/core/slide.rs +++ b/src/core/slide.rs @@ -1,11 +1,9 @@ use crisp::types::{Keyword, Symbol, Value}; -use miette::{miette, IntoDiagnostic, Result}; +use miette::{miette, Result}; use serde::{Deserialize, Serialize}; use std::{ - collections::HashMap, fmt::Display, path::{Path, PathBuf}, - str::FromStr, }; use tracing::error; @@ -381,7 +379,7 @@ pub fn lisp_to_background(lisp: &Value) -> Background { panic!("Should always be there"); }; let mut home = home.to_string(); - home.push_str("/"); + home.push('/'); let s = s.replace("./", &home); match Background::try_from(s.as_str()) { diff --git a/src/core/songs.rs b/src/core/songs.rs index a60fede..50b48d2 100644 --- a/src/core/songs.rs +++ b/src/core/songs.rs @@ -1,11 +1,11 @@ -use std::{collections::HashMap, fmt::Display, path::PathBuf}; +use std::{collections::HashMap, path::PathBuf}; -use cosmic::{executor, iced::Executor}; +use cosmic::iced::Executor; use crisp::types::{Keyword, Symbol, Value}; use miette::{miette, IntoDiagnostic, Result}; use serde::{Deserialize, Serialize}; use sqlx::{ - query, query_as, sqlite::SqliteRow, FromRow, Row, + query, sqlite::SqliteRow, FromRow, Row, SqliteConnection, }; use tracing::{debug, error}; @@ -154,7 +154,7 @@ pub fn lisp_to_song(list: Vec) -> Song { .position(|v| v == &Value::Keyword(Keyword::from("id"))) { let pos = key_pos + 1; - list.get(pos).map(|c| i32::from(c)).unwrap_or_default() + list.get(pos).map(i32::from).unwrap_or_default() } else { DEFAULT_SONG_ID }; @@ -164,7 +164,7 @@ pub fn lisp_to_song(list: Vec) -> Song { v == &Value::Keyword(Keyword::from("background")) }) { let pos = key_pos + 1; - list.get(pos).map(|b| slide::lisp_to_background(b)) + list.get(pos).map(slide::lisp_to_background) } else { None }; @@ -174,7 +174,7 @@ pub fn lisp_to_song(list: Vec) -> Song { .position(|v| v == &Value::Keyword(Keyword::from("author"))) { let pos = key_pos + 1; - list.get(pos).map(|a| String::from(a)) + list.get(pos).map(String::from) } else { None }; @@ -204,7 +204,7 @@ pub fn lisp_to_song(list: Vec) -> Song { .position(|v| v == &Value::Keyword(Keyword::from("font"))) { let pos = key_pos + 1; - list.get(pos).map(|f| String::from(f)) + list.get(pos).map(String::from) } else { None }; @@ -213,7 +213,7 @@ pub fn lisp_to_song(list: Vec) -> Song { v == &Value::Keyword(Keyword::from("font-size")) }) { let pos = key_pos + 1; - list.get(pos).map(|f| i32::from(f)) + list.get(pos).map(i32::from) } else { None }; @@ -224,7 +224,7 @@ pub fn lisp_to_song(list: Vec) -> Song { { let pos = key_pos + 1; list.get(pos) - .map(|t| String::from(t)) + .map(String::from) .unwrap_or(String::from("song")) } else { String::from("song") @@ -235,7 +235,7 @@ pub fn lisp_to_song(list: Vec) -> Song { v == &Value::Keyword(Keyword::from("text-alignment")) }) { let pos = key_pos + 1; - list.get(pos).map(|t| TextAlignment::from(t)) + list.get(pos).map(TextAlignment::from) } else { None }; @@ -247,7 +247,7 @@ pub fn lisp_to_song(list: Vec) -> Song { let pos = key_pos + 1; list.get(pos).map(|v| match v { Value::List(vals) => vals - .into_iter() + .iter() .map(|v| String::from(v).to_uppercase()) .collect::>(), _ => vec![], @@ -256,8 +256,7 @@ pub fn lisp_to_song(list: Vec) -> Song { None }; - let first_text_postiion = if let Some(pos) = - list.iter().position(|v| match v { + let first_text_postiion = list.iter().position(|v| match v { Value::List(inner) => { (match &inner[0] { Value::Symbol(Symbol(text)) => { @@ -273,11 +272,7 @@ pub fn lisp_to_song(list: Vec) -> Song { }) } _ => false, - }) { - pos - } else { - 1 - }; + }).unwrap_or(1); let lyric_elements = &list[first_text_postiion..]; @@ -347,7 +342,7 @@ pub async fn get_song_from_db( db: &mut SqliteConnection, ) -> Result { let row = query(r#"SELECT verse_order as "verse_order!", font_size as "font_size!: i32", background_type as "background_type!", horizontal_text_alignment as "horizontal_text_alignment!", vertical_text_alignment as "vertical_text_alignment!", title as "title!", font as "font!", background as "background!", lyrics as "lyrics!", ccli as "ccli!", author as "author!", audio as "audio!", id as "id: i32" from songs where id = $1"#).bind(index).fetch_one(db).await.into_diagnostic()?; - Ok(Song::from_row(&row).into_diagnostic()?) + Song::from_row(&row).into_diagnostic() } impl Model { diff --git a/src/core/videos.rs b/src/core/videos.rs index 54ea246..c41a1e1 100644 --- a/src/core/videos.rs +++ b/src/core/videos.rs @@ -3,9 +3,9 @@ use crate::{Background, SlideBuilder, TextAlignment}; use super::{ model::Model, service_items::ServiceTrait, slide::Slide, }; -use cosmic::{executor, iced::Executor}; +use cosmic::iced::Executor; use crisp::types::{Keyword, Value}; -use miette::{miette, IntoDiagnostic, Result}; +use miette::{IntoDiagnostic, Result}; use serde::{Deserialize, Serialize}; use sqlx::{query_as, SqliteConnection}; use std::path::PathBuf; @@ -83,7 +83,7 @@ impl From<&Value> for Video { let pos = loop_pos + 1; list.get(pos) .map(|l| { - String::from(l) == "true".to_string() + String::from(l) == *"true" }) .unwrap_or_default() } else { @@ -157,7 +157,7 @@ pub async fn get_video_from_db( database_id: i32, db: &mut SqliteConnection, ) -> Result