From 7827d7f7221345e0c271e0886f202e4771390f5c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matou=C5=A1=20Volf?= <66163112+matous-volf@users.noreply.github.com> Date: Sun, 8 Sep 2024 08:21:33 +0200 Subject: [PATCH] style: use `Self` in error enum `impl`s --- src/errors/error.rs | 4 ++-- src/errors/project_error.rs | 4 ++-- src/errors/task_error.rs | 8 ++++---- 3 files changed, 8 insertions(+), 8 deletions(-) diff --git a/src/errors/error.rs b/src/errors/error.rs index a26a41b..993dd7e 100644 --- a/src/errors/error.rs +++ b/src/errors/error.rs @@ -11,7 +11,7 @@ pub enum Error { impl Display for Error { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { match self { - Error::ServerInternal => write!(f, "internal server error"), + Self::ServerInternal => write!(f, "internal server error"), } } } @@ -22,7 +22,7 @@ impl FromStr for Error { fn from_str(s: &str) -> Result { Ok(match s { - "internal server error" => Error::ServerInternal, + "internal server error" => Self::ServerInternal, _ => return Err(()), }) } diff --git a/src/errors/project_error.rs b/src/errors/project_error.rs index f93283f..7bf5503 100644 --- a/src/errors/project_error.rs +++ b/src/errors/project_error.rs @@ -36,7 +36,7 @@ impl From for ErrorVec { impl From for ProjectError { fn from(_: diesel::result::Error) -> Self { - ProjectError::Error(Error::ServerInternal) + Self::Error(Error::ServerInternal) } } @@ -52,6 +52,6 @@ impl FromStr for ProjectError { type Err = (); fn from_str(_: &str) -> Result { - Ok(ProjectError::Error(Error::ServerInternal)) + Ok(Self::Error(Error::ServerInternal)) } } diff --git a/src/errors/task_error.rs b/src/errors/task_error.rs index a769de9..d745550 100644 --- a/src/errors/task_error.rs +++ b/src/errors/task_error.rs @@ -42,12 +42,12 @@ impl From for TaskError { diesel::result::DatabaseErrorKind::ForeignKeyViolation, info ) => { match info.constraint_name() { - Some("tasks_project_id_fkey") => TaskError::ProjectNotFound, - _ => TaskError::Error(Error::ServerInternal) + Some("tasks_project_id_fkey") => Self::ProjectNotFound, + _ => Self::Error(Error::ServerInternal) } } _ => { - TaskError::Error(Error::ServerInternal) + Self::Error(Error::ServerInternal) } } } @@ -65,6 +65,6 @@ impl FromStr for TaskError { type Err = (); fn from_str(_: &str) -> Result { - Ok(TaskError::Error(Error::ServerInternal)) + Ok(Self::Error(Error::ServerInternal)) } }