good structure

This commit is contained in:
2025-03-13 21:58:48 +01:00
parent c750dbd8f1
commit 663f395c6e
5 changed files with 59 additions and 1 deletions
+11
View File
@@ -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
}
}