vite_rust/
error.rs

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
use serde::Deserialize;
use std::{error::Error, fmt};

#[derive(Debug, Deserialize)]
pub enum ViteErrorKind {
    Manifest,
}

#[derive(Debug, Deserialize)]
#[allow(unused)]
pub struct ViteError {
    cause: Box<str>,
    kind: ViteErrorKind,
}

impl ViteError {
    pub fn new<T>(cause: T, kind: ViteErrorKind) -> Self
    where
        T: ToString,
    {
        ViteError {
            cause: cause.to_string().into_boxed_str(),
            kind,
        }
    }
}

impl fmt::Display for ViteError {
    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
        write!(f, "{}", self.cause)
    }
}

impl Error for ViteError {}