use std::fmt;
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct Error {
kind: Kind,
message: String,
}
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
enum Kind {
ConnectionString,
Connect,
Query,
Sql,
}
impl Error {
pub(crate) fn connection_string(message: impl Into<String>) -> Self {
Error { kind: Kind::ConnectionString, message: message.into() }
}
pub(crate) fn connect(message: impl Into<String>) -> Self {
Error { kind: Kind::Connect, message: message.into() }
}
pub(crate) fn query(message: impl Into<String>) -> Self {
Error { kind: Kind::Query, message: message.into() }
}
pub(crate) fn sql(message: impl Into<String>) -> Self {
Error { kind: Kind::Sql, message: message.into() }
}
#[must_use]
pub fn is_connection_string(&self) -> bool {
self.kind == Kind::ConnectionString
}
#[must_use]
pub fn is_connect(&self) -> bool {
self.kind == Kind::Connect
}
#[must_use]
pub fn is_query(&self) -> bool {
self.kind == Kind::Query
}
#[must_use]
pub fn is_sql(&self) -> bool {
self.kind == Kind::Sql
}
}
impl fmt::Display for Error {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
f.write_str(&self.message)
}
}
impl std::error::Error for Error {}