diff --git a/visions/server/Taskfile.yml b/visions/server/Taskfile.yml index d54c919..df7c99e 100644 --- a/visions/server/Taskfile.yml +++ b/visions/server/Taskfile.yml @@ -7,9 +7,17 @@ tasks: test: cmds: - # - cargo watch -x 'test -- --nocapture' - cargo watch -x 'nextest run' dev: cmds: - cargo watch -x run + + lint: + cmds: + - cargo watch -x clippy + + release: + cmds: + - task lint + - cargo build --release diff --git a/visions/server/src/asset_db.rs b/visions/server/src/asset_db.rs index 7b7a786..c84e5c9 100644 --- a/visions/server/src/asset_db.rs +++ b/visions/server/src/asset_db.rs @@ -15,7 +15,7 @@ pub enum Error { Inaccessible, #[error("An unexpected IO error occured when retrieving an asset {0}")] - UnexpectedError(std::io::Error), + Unexpected(std::io::Error), } impl From for Error { @@ -25,7 +25,7 @@ impl From for Error { match err.kind() { NotFound => Error::NotFound, PermissionDenied | UnexpectedEof => Error::Inaccessible, - _ => Error::UnexpectedError(err), + _ => Error::Unexpected(err), } } } @@ -35,7 +35,7 @@ impl From for Error { pub struct AssetId(String); impl AssetId { - pub fn as_str<'a>(&'a self) -> &'a str { + pub fn as_str(&self) -> &str { &self.0 } } @@ -69,7 +69,7 @@ impl<'a> Iterator for AssetIter<'a> { } pub trait Assets { - fn assets<'a>(&'a self) -> AssetIter<'a>; + fn assets(&self) -> AssetIter; fn get(&self, asset_id: AssetId) -> Result<(Mime, Vec), Error>; } @@ -95,7 +95,7 @@ impl FsAssets { } impl Assets for FsAssets { - fn assets<'a>(&'a self) -> AssetIter<'a> { + fn assets(&self) -> AssetIter { AssetIter(self.assets.iter()) } @@ -104,9 +104,9 @@ impl Assets for FsAssets { Some(asset) => Ok(asset), None => Err(Error::NotFound), }?; - let mime = mime_guess::from_path(&path).first().unwrap(); + let mime = mime_guess::from_path(path).first().unwrap(); let mut content: Vec = Vec::new(); - let mut file = std::fs::File::open(&path)?; + let mut file = std::fs::File::open(path)?; file.read_to_end(&mut content)?; Ok((mime, content)) } diff --git a/visions/server/src/core.rs b/visions/server/src/core.rs index 99eea4a..03937de 100644 --- a/visions/server/src/core.rs +++ b/visions/server/src/core.rs @@ -11,10 +11,10 @@ use uuid::Uuid; use crate::{ asset_db::{self, AssetId, Assets}, database::{CharacterId, Database, SessionId, UserId}, - types::{AppError, FatalError, Game, Message, Tabletop, User, RGB}, + types::{AppError, FatalError, Game, Message, Tabletop, User, Rgb}, }; -const DEFAULT_BACKGROUND_COLOR: RGB = RGB { +const DEFAULT_BACKGROUND_COLOR: Rgb = Rgb { red: 0xca, green: 0xb9, blue: 0xbb, @@ -60,7 +60,7 @@ impl Core { } pub async fn status(&self) -> ResultExt { - let mut state = self.0.write().await; + let state = self.0.write().await; let admin_user = return_error!(match state.db.user(&UserId::from("admin")).await { Ok(Some(admin_user)) => ok(admin_user), Ok(None) => { @@ -121,7 +121,7 @@ impl Core { pub async fn list_users(&self) -> ResultExt, AppError, FatalError> { let users = self.0.write().await.db.users().await; match users { - Ok(users) => ok(users.into_iter().map(|u| User::from(u)).collect()), + Ok(users) => ok(users.into_iter().map(User::from).collect()), Err(err) => fatal(err), } } @@ -130,7 +130,7 @@ impl Core { let games = self.0.write().await.db.games().await; match games { // Ok(games) => ok(games.into_iter().map(|g| Game::from(g)).collect()), - Ok(games) => unimplemented!(), + Ok(_games) => unimplemented!(), Err(err) => fatal(err), } } @@ -154,7 +154,7 @@ impl Core { asset_db::Error::Inaccessible => { AppError::Inaccessible(format!("{}", asset_id)) } - asset_db::Error::UnexpectedError(err) => { + asset_db::Error::Unexpected(err) => { AppError::Inaccessible(format!("{}", err)) } }), @@ -168,7 +168,7 @@ impl Core { .asset_store .assets() .filter_map( - |(asset_id, value)| match mime_guess::from_path(&value).first() { + |(asset_id, value)| match mime_guess::from_path(value).first() { Some(mime) if mime.type_() == mime::IMAGE => Some(asset_id.clone()), _ => None, }, @@ -217,7 +217,7 @@ impl Core { uuid: UserId, password: String, ) -> ResultExt<(), AppError, FatalError> { - let mut state = self.0.write().await; + let state = self.0.write().await; let user = match state.db.user(&uuid).await { Ok(Some(row)) => row, Ok(None) => return error(AppError::NotFound(uuid.as_str().to_owned())), @@ -239,7 +239,7 @@ impl Core { password: &str, ) -> ResultExt { let state = self.0.write().await; - match state.db.user_by_username(&username).await { + match state.db.user_by_username(username).await { Ok(Some(row)) if (row.password == password) => { let session_id = state.db.create_session(row.id).await.unwrap(); ok(session_id) diff --git a/visions/server/src/database/types.rs b/visions/server/src/database/types.rs index 9909365..55b3490 100644 --- a/visions/server/src/database/types.rs +++ b/visions/server/src/database/types.rs @@ -10,7 +10,7 @@ impl UserId { Self(format!("{}", Uuid::new_v4().hyphenated())) } - pub fn as_str<'a>(&'a self) -> &'a str { + pub fn as_str(&self) -> &str { &self.0 } } @@ -44,7 +44,7 @@ impl SessionId { Self(format!("{}", Uuid::new_v4().hyphenated())) } - pub fn as_str<'a>(&'a self) -> &'a str { + pub fn as_str(&self) -> &str { &self.0 } } @@ -78,7 +78,7 @@ impl GameId { Self(format!("{}", Uuid::new_v4().hyphenated())) } - pub fn as_str<'a>(&'a self) -> &'a str { + pub fn as_str(&self) -> &str { &self.0 } } @@ -112,7 +112,7 @@ impl CharacterId { Self(format!("{}", Uuid::new_v4().hyphenated())) } - pub fn as_str<'a>(&'a self) -> &'a str { + pub fn as_str(&self) -> &str { &self.0 } } diff --git a/visions/server/src/types.rs b/visions/server/src/types.rs index 15fedf4..7ea62b4 100644 --- a/visions/server/src/types.rs +++ b/visions/server/src/types.rs @@ -52,7 +52,7 @@ pub enum AppError { #[derive(Clone, Debug, Deserialize, PartialEq, Serialize)] #[serde(rename_all = "camelCase")] #[typeshare] -pub struct RGB { +pub struct Rgb { pub red: u32, pub green: u32, pub blue: u32, @@ -109,7 +109,7 @@ pub struct Game { #[serde(rename_all = "camelCase")] #[typeshare] pub struct Tabletop { - pub background_color: RGB, + pub background_color: Rgb, pub background_image: Option, }