changelog shortlog graph tags branches changeset files revisions annotate raw help

Mercurial > core / rust/lib/db/src/err.rs

changeset 698: 96958d3eb5b0
parent: 3d78bed56188
author: Richard Westhaver <ellis@rwest.io>
date: Fri, 04 Oct 2024 22:04:59 -0400
permissions: -rw-r--r--
description: fixes
1 //! db errors
2 use std::{fmt, io};
3 
4 /// db Result type
5 pub type Result<T> = std::result::Result<T, Error>;
6 
7 /// db Error type
8 pub enum Error {
9  Io(io::Error),
10  #[cfg(feature = "rocksdb")]
11  Rocksdb(rocksdb::Error),
12 }
13 
14 impl From<io::Error> for Error {
15  fn from(e: io::Error) -> Self {
16  Error::Io(e)
17  }
18 }
19 
20 #[cfg(feature = "rocksdb")]
21 impl From<rocksdb::Error> for Error {
22  fn from(e: rocksdb::Error) -> Self {
23  Error::Rocksdb(e)
24  }
25 }
26 
27 impl fmt::Display for Error {
28  fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
29  match *self {
30  Error::Io(ref err) => write!(f, "IO error: {}", err),
31  #[cfg(feature = "rocksdb")]
32  Error::Rocksdb(ref err) => write!(f, "RocksDB error: {}", err),
33  }
34  }
35 }
36 
37 impl fmt::Debug for Error {
38  fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
39  match *self {
40  Error::Io(ref err) => write!(f, "IO error: {}", err),
41  #[cfg(feature = "rocksdb")]
42  Error::Rocksdb(ref err) => write!(f, "RocksDB error: {}", err),
43  }
44  }
45 }
46 
47 impl std::error::Error for Error {}