style: use Self in error enum impls

This commit is contained in:
Matouš Volf 2024-09-08 08:21:33 +02:00
parent 0299092fa7
commit 7827d7f722
3 changed files with 8 additions and 8 deletions

View File

@ -11,7 +11,7 @@ pub enum Error {
impl Display for Error { impl Display for Error {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match self { 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<Self, Self::Err> { fn from_str(s: &str) -> Result<Self, Self::Err> {
Ok(match s { Ok(match s {
"internal server error" => Error::ServerInternal, "internal server error" => Self::ServerInternal,
_ => return Err(()), _ => return Err(()),
}) })
} }

View File

@ -36,7 +36,7 @@ impl From<ValidationErrors> for ErrorVec<ProjectError> {
impl From<diesel::result::Error> for ProjectError { impl From<diesel::result::Error> for ProjectError {
fn from(_: diesel::result::Error) -> Self { fn from(_: diesel::result::Error) -> Self {
ProjectError::Error(Error::ServerInternal) Self::Error(Error::ServerInternal)
} }
} }
@ -52,6 +52,6 @@ impl FromStr for ProjectError {
type Err = (); type Err = ();
fn from_str(_: &str) -> Result<Self, Self::Err> { fn from_str(_: &str) -> Result<Self, Self::Err> {
Ok(ProjectError::Error(Error::ServerInternal)) Ok(Self::Error(Error::ServerInternal))
} }
} }

View File

@ -42,12 +42,12 @@ impl From<diesel::result::Error> for TaskError {
diesel::result::DatabaseErrorKind::ForeignKeyViolation, info diesel::result::DatabaseErrorKind::ForeignKeyViolation, info
) => { ) => {
match info.constraint_name() { match info.constraint_name() {
Some("tasks_project_id_fkey") => TaskError::ProjectNotFound, Some("tasks_project_id_fkey") => Self::ProjectNotFound,
_ => TaskError::Error(Error::ServerInternal) _ => Self::Error(Error::ServerInternal)
} }
} }
_ => { _ => {
TaskError::Error(Error::ServerInternal) Self::Error(Error::ServerInternal)
} }
} }
} }
@ -65,6 +65,6 @@ impl FromStr for TaskError {
type Err = (); type Err = ();
fn from_str(_: &str) -> Result<Self, Self::Err> { fn from_str(_: &str) -> Result<Self, Self::Err> {
Ok(TaskError::Error(Error::ServerInternal)) Ok(Self::Error(Error::ServerInternal))
} }
} }