Resolve many warnings
This commit is contained in:
parent
a18cdb0710
commit
a33b94e5b3
@ -7,9 +7,17 @@ tasks:
|
|||||||
|
|
||||||
test:
|
test:
|
||||||
cmds:
|
cmds:
|
||||||
# - cargo watch -x 'test -- --nocapture'
|
|
||||||
- cargo watch -x 'nextest run'
|
- cargo watch -x 'nextest run'
|
||||||
|
|
||||||
dev:
|
dev:
|
||||||
cmds:
|
cmds:
|
||||||
- cargo watch -x run
|
- cargo watch -x run
|
||||||
|
|
||||||
|
lint:
|
||||||
|
cmds:
|
||||||
|
- cargo watch -x clippy
|
||||||
|
|
||||||
|
release:
|
||||||
|
cmds:
|
||||||
|
- task lint
|
||||||
|
- cargo build --release
|
||||||
|
@ -15,7 +15,7 @@ pub enum Error {
|
|||||||
Inaccessible,
|
Inaccessible,
|
||||||
|
|
||||||
#[error("An unexpected IO error occured when retrieving an asset {0}")]
|
#[error("An unexpected IO error occured when retrieving an asset {0}")]
|
||||||
UnexpectedError(std::io::Error),
|
Unexpected(std::io::Error),
|
||||||
}
|
}
|
||||||
|
|
||||||
impl From<std::io::Error> for Error {
|
impl From<std::io::Error> for Error {
|
||||||
@ -25,7 +25,7 @@ impl From<std::io::Error> for Error {
|
|||||||
match err.kind() {
|
match err.kind() {
|
||||||
NotFound => Error::NotFound,
|
NotFound => Error::NotFound,
|
||||||
PermissionDenied | UnexpectedEof => Error::Inaccessible,
|
PermissionDenied | UnexpectedEof => Error::Inaccessible,
|
||||||
_ => Error::UnexpectedError(err),
|
_ => Error::Unexpected(err),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -35,7 +35,7 @@ impl From<std::io::Error> for Error {
|
|||||||
pub struct AssetId(String);
|
pub struct AssetId(String);
|
||||||
|
|
||||||
impl AssetId {
|
impl AssetId {
|
||||||
pub fn as_str<'a>(&'a self) -> &'a str {
|
pub fn as_str(&self) -> &str {
|
||||||
&self.0
|
&self.0
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -69,7 +69,7 @@ impl<'a> Iterator for AssetIter<'a> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub trait Assets {
|
pub trait Assets {
|
||||||
fn assets<'a>(&'a self) -> AssetIter<'a>;
|
fn assets(&self) -> AssetIter;
|
||||||
|
|
||||||
fn get(&self, asset_id: AssetId) -> Result<(Mime, Vec<u8>), Error>;
|
fn get(&self, asset_id: AssetId) -> Result<(Mime, Vec<u8>), Error>;
|
||||||
}
|
}
|
||||||
@ -95,7 +95,7 @@ impl FsAssets {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl Assets for FsAssets {
|
impl Assets for FsAssets {
|
||||||
fn assets<'a>(&'a self) -> AssetIter<'a> {
|
fn assets(&self) -> AssetIter {
|
||||||
AssetIter(self.assets.iter())
|
AssetIter(self.assets.iter())
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -104,9 +104,9 @@ impl Assets for FsAssets {
|
|||||||
Some(asset) => Ok(asset),
|
Some(asset) => Ok(asset),
|
||||||
None => Err(Error::NotFound),
|
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<u8> = Vec::new();
|
let mut content: Vec<u8> = Vec::new();
|
||||||
let mut file = std::fs::File::open(&path)?;
|
let mut file = std::fs::File::open(path)?;
|
||||||
file.read_to_end(&mut content)?;
|
file.read_to_end(&mut content)?;
|
||||||
Ok((mime, content))
|
Ok((mime, content))
|
||||||
}
|
}
|
||||||
|
@ -11,10 +11,10 @@ use uuid::Uuid;
|
|||||||
use crate::{
|
use crate::{
|
||||||
asset_db::{self, AssetId, Assets},
|
asset_db::{self, AssetId, Assets},
|
||||||
database::{CharacterId, Database, SessionId, UserId},
|
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,
|
red: 0xca,
|
||||||
green: 0xb9,
|
green: 0xb9,
|
||||||
blue: 0xbb,
|
blue: 0xbb,
|
||||||
@ -60,7 +60,7 @@ impl Core {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub async fn status(&self) -> ResultExt<Status, AppError, FatalError> {
|
pub async fn status(&self) -> ResultExt<Status, AppError, FatalError> {
|
||||||
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 {
|
let admin_user = return_error!(match state.db.user(&UserId::from("admin")).await {
|
||||||
Ok(Some(admin_user)) => ok(admin_user),
|
Ok(Some(admin_user)) => ok(admin_user),
|
||||||
Ok(None) => {
|
Ok(None) => {
|
||||||
@ -121,7 +121,7 @@ impl Core {
|
|||||||
pub async fn list_users(&self) -> ResultExt<Vec<User>, AppError, FatalError> {
|
pub async fn list_users(&self) -> ResultExt<Vec<User>, AppError, FatalError> {
|
||||||
let users = self.0.write().await.db.users().await;
|
let users = self.0.write().await.db.users().await;
|
||||||
match users {
|
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),
|
Err(err) => fatal(err),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -130,7 +130,7 @@ impl Core {
|
|||||||
let games = self.0.write().await.db.games().await;
|
let games = self.0.write().await.db.games().await;
|
||||||
match games {
|
match games {
|
||||||
// Ok(games) => ok(games.into_iter().map(|g| Game::from(g)).collect()),
|
// Ok(games) => ok(games.into_iter().map(|g| Game::from(g)).collect()),
|
||||||
Ok(games) => unimplemented!(),
|
Ok(_games) => unimplemented!(),
|
||||||
Err(err) => fatal(err),
|
Err(err) => fatal(err),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -154,7 +154,7 @@ impl Core {
|
|||||||
asset_db::Error::Inaccessible => {
|
asset_db::Error::Inaccessible => {
|
||||||
AppError::Inaccessible(format!("{}", asset_id))
|
AppError::Inaccessible(format!("{}", asset_id))
|
||||||
}
|
}
|
||||||
asset_db::Error::UnexpectedError(err) => {
|
asset_db::Error::Unexpected(err) => {
|
||||||
AppError::Inaccessible(format!("{}", err))
|
AppError::Inaccessible(format!("{}", err))
|
||||||
}
|
}
|
||||||
}),
|
}),
|
||||||
@ -168,7 +168,7 @@ impl Core {
|
|||||||
.asset_store
|
.asset_store
|
||||||
.assets()
|
.assets()
|
||||||
.filter_map(
|
.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()),
|
Some(mime) if mime.type_() == mime::IMAGE => Some(asset_id.clone()),
|
||||||
_ => None,
|
_ => None,
|
||||||
},
|
},
|
||||||
@ -217,7 +217,7 @@ impl Core {
|
|||||||
uuid: UserId,
|
uuid: UserId,
|
||||||
password: String,
|
password: String,
|
||||||
) -> ResultExt<(), AppError, FatalError> {
|
) -> ResultExt<(), AppError, FatalError> {
|
||||||
let mut state = self.0.write().await;
|
let state = self.0.write().await;
|
||||||
let user = match state.db.user(&uuid).await {
|
let user = match state.db.user(&uuid).await {
|
||||||
Ok(Some(row)) => row,
|
Ok(Some(row)) => row,
|
||||||
Ok(None) => return error(AppError::NotFound(uuid.as_str().to_owned())),
|
Ok(None) => return error(AppError::NotFound(uuid.as_str().to_owned())),
|
||||||
@ -239,7 +239,7 @@ impl Core {
|
|||||||
password: &str,
|
password: &str,
|
||||||
) -> ResultExt<SessionId, AppError, FatalError> {
|
) -> ResultExt<SessionId, AppError, FatalError> {
|
||||||
let state = self.0.write().await;
|
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) => {
|
Ok(Some(row)) if (row.password == password) => {
|
||||||
let session_id = state.db.create_session(row.id).await.unwrap();
|
let session_id = state.db.create_session(row.id).await.unwrap();
|
||||||
ok(session_id)
|
ok(session_id)
|
||||||
|
@ -10,7 +10,7 @@ impl UserId {
|
|||||||
Self(format!("{}", Uuid::new_v4().hyphenated()))
|
Self(format!("{}", Uuid::new_v4().hyphenated()))
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn as_str<'a>(&'a self) -> &'a str {
|
pub fn as_str(&self) -> &str {
|
||||||
&self.0
|
&self.0
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -44,7 +44,7 @@ impl SessionId {
|
|||||||
Self(format!("{}", Uuid::new_v4().hyphenated()))
|
Self(format!("{}", Uuid::new_v4().hyphenated()))
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn as_str<'a>(&'a self) -> &'a str {
|
pub fn as_str(&self) -> &str {
|
||||||
&self.0
|
&self.0
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -78,7 +78,7 @@ impl GameId {
|
|||||||
Self(format!("{}", Uuid::new_v4().hyphenated()))
|
Self(format!("{}", Uuid::new_v4().hyphenated()))
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn as_str<'a>(&'a self) -> &'a str {
|
pub fn as_str(&self) -> &str {
|
||||||
&self.0
|
&self.0
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -112,7 +112,7 @@ impl CharacterId {
|
|||||||
Self(format!("{}", Uuid::new_v4().hyphenated()))
|
Self(format!("{}", Uuid::new_v4().hyphenated()))
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn as_str<'a>(&'a self) -> &'a str {
|
pub fn as_str(&self) -> &str {
|
||||||
&self.0
|
&self.0
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -52,7 +52,7 @@ pub enum AppError {
|
|||||||
#[derive(Clone, Debug, Deserialize, PartialEq, Serialize)]
|
#[derive(Clone, Debug, Deserialize, PartialEq, Serialize)]
|
||||||
#[serde(rename_all = "camelCase")]
|
#[serde(rename_all = "camelCase")]
|
||||||
#[typeshare]
|
#[typeshare]
|
||||||
pub struct RGB {
|
pub struct Rgb {
|
||||||
pub red: u32,
|
pub red: u32,
|
||||||
pub green: u32,
|
pub green: u32,
|
||||||
pub blue: u32,
|
pub blue: u32,
|
||||||
@ -109,7 +109,7 @@ pub struct Game {
|
|||||||
#[serde(rename_all = "camelCase")]
|
#[serde(rename_all = "camelCase")]
|
||||||
#[typeshare]
|
#[typeshare]
|
||||||
pub struct Tabletop {
|
pub struct Tabletop {
|
||||||
pub background_color: RGB,
|
pub background_color: Rgb,
|
||||||
pub background_image: Option<AssetId>,
|
pub background_image: Option<AssetId>,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user