koibumi_common_sync/
node.rs1use std::{fmt, io, path::PathBuf};
4
5use log::debug;
6
7use crate::{config::create_data_dir, param::Params};
8
9#[derive(Debug)]
11pub enum Error {
12 IoError(io::Error),
15 RusqliteError(rusqlite::Error),
18}
19
20impl fmt::Display for Error {
21 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
22 match self {
23 Self::IoError(err) => err.fmt(f),
24 Self::RusqliteError(err) => err.fmt(f),
25 }
26 }
27}
28
29impl std::error::Error for Error {}
30
31impl From<io::Error> for Error {
32 fn from(err: io::Error) -> Self {
33 Self::IoError(err)
34 }
35}
36
37impl From<rusqlite::Error> for Error {
38 fn from(err: rusqlite::Error) -> Self {
39 Self::RusqliteError(err)
40 }
41}
42
43pub fn prepare(params: &Params) -> Result<PathBuf, Error> {
45 let mut path = create_data_dir(params)?;
46 path.push("node.db");
47 debug!("db: {:?}", path);
48 Ok(path)
49}