space_lib/
error.rs

1use serde::{Serialize, Deserialize};
2
3// Error type
4#[derive(Debug, Serialize, Deserialize)]
5pub struct Error {
6    description: String,
7}
8
9impl Error {
10    pub fn new<T: std::fmt::Display>(message: T) -> Self {
11        Self {
12            description: message.to_string(),
13        }
14    }
15}
16
17impl<T: std::fmt::Display> From<T> for Error {
18    fn from(value: T) -> Self {
19        Self {
20            description: value.to_string(),
21        }
22    }
23}
24
25// Result type
26pub type Result<T, E = Error> = std::result::Result<T, E>;