Start rust rewrite
This commit is contained in:
commit
12d57d020f
22 changed files with 2599 additions and 0 deletions
src/db
30
src/db/errors.rs
Normal file
30
src/db/errors.rs
Normal file
|
@ -0,0 +1,30 @@
|
|||
use serde::ser::SerializeStruct;
|
||||
use serde::{Serialize, Serializer};
|
||||
|
||||
pub enum DatabaseError {
|
||||
InsertError,
|
||||
InsertGetError,
|
||||
}
|
||||
|
||||
impl Serialize for DatabaseError {
|
||||
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
|
||||
where
|
||||
S: Serializer,
|
||||
{
|
||||
let mut s = serializer.serialize_struct("error", 2)?;
|
||||
s.serialize_field("code", &500)?;
|
||||
s.serialize_field("description", &String::from(self))?;
|
||||
s.end()
|
||||
}
|
||||
}
|
||||
|
||||
impl From<&DatabaseError> for String {
|
||||
fn from(err: &DatabaseError) -> Self {
|
||||
match err {
|
||||
DatabaseError::InsertError => String::from("error inserting into database"),
|
||||
DatabaseError::InsertGetError => {
|
||||
String::from("error retrieving new entry from database (your entry was saved)")
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue