turtle_build/infrastructure/database/
error.rs1use core::{fmt::Display, str::Utf8Error};
2use rkyv::rancor;
3use thiserror::Error;
4
5#[derive(Clone, Debug, Eq, Error, PartialEq)]
7#[error("{0}")]
8pub struct DatabaseError(String);
9
10impl DatabaseError {
11 pub fn new(error: impl Display) -> Self {
13 Self(error.to_string())
14 }
15}
16
17impl From<fjall::Error> for DatabaseError {
18 fn from(error: fjall::Error) -> Self {
19 Self::new(error)
20 }
21}
22
23impl From<rancor::Error> for DatabaseError {
24 fn from(error: rancor::Error) -> Self {
25 Self::new(error)
26 }
27}
28
29impl From<redb::Error> for DatabaseError {
30 fn from(error: redb::Error) -> Self {
31 Self::new(error)
32 }
33}
34
35impl From<Utf8Error> for DatabaseError {
36 fn from(error: Utf8Error) -> Self {
37 Self::new(error)
38 }
39}
40
41#[cfg(test)]
42mod tests {
43 use super::*;
44
45 #[test]
46 fn display() {
47 assert_eq!(
48 DatabaseError::new("database not initialized").to_string(),
49 "database not initialized"
50 );
51 }
52}