good structure
This commit is contained in:
@@ -4,6 +4,7 @@ pub type Result<T = Response> = std::result::Result<T, Error>;
|
||||
pub enum Response {
|
||||
Pong,
|
||||
Success,
|
||||
Player { cloak: String },
|
||||
}
|
||||
|
||||
impl std::fmt::Display for Response {
|
||||
@@ -11,6 +12,7 @@ impl std::fmt::Display for Response {
|
||||
match self {
|
||||
Response::Pong => write!(f, "Pong"),
|
||||
Response::Success => write!(f, "Success"),
|
||||
Response::Player { cloak } => write!(f, "@cloak={cloak}"),
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -23,6 +25,7 @@ pub enum Error {
|
||||
ParameterNotFound,
|
||||
InvalidSession,
|
||||
InvalidHandshake,
|
||||
DatabaseError,
|
||||
}
|
||||
|
||||
impl std::fmt::Display for Error {
|
||||
@@ -34,6 +37,14 @@ impl std::fmt::Display for Error {
|
||||
Error::ParameterNotFound => write!(f, "Parameter not found"),
|
||||
Error::InvalidSession => write!(f, "Invalid session"),
|
||||
Error::InvalidHandshake => write!(f, "Invalid handshake"),
|
||||
Error::DatabaseError => write!(f, "Database error"),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl From<mongodb::error::Error> for Error {
|
||||
fn from(e: mongodb::error::Error) -> Self {
|
||||
println!("{e}");
|
||||
Error::DatabaseError
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user