hot_restart/error/
impl.rs

1use crate::*;
2
3/// Implementation of Display trait for HotRestartError.
4impl fmt::Display for HotRestartError {
5    /// Formats the error message for display.
6    ///
7    /// # Arguments
8    ///
9    /// - `&Self` - The HotRestartError instance.
10    /// - `&mut fmt::Formatter` - The formatter to write to.
11    ///
12    /// # Returns
13    ///
14    /// - `fmt::Result` - Result of formatting operation.
15    #[inline(always)]
16    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
17        match self {
18            HotRestartError::CargoWatchNotInstalled => write!(
19                f,
20                "Cargo-watch is not installed. Please install it using: cargo install cargo-watch"
21            ),
22            HotRestartError::CommandSpawnFailed(e) => {
23                write!(f, "Failed to spawn cargo watch command: {e}")
24            }
25            HotRestartError::CommandWaitFailed(e) => {
26                write!(f, "Failed to wait for cargo watch command: {e}")
27            }
28            HotRestartError::Other(e) => write!(f, "An unexpected error occurred: {e}"),
29        }
30    }
31}
32
33/// Implementation of From trait for converting Error to HotRestartError.
34impl From<Error> for HotRestartError {
35    /// Converts a generic Error into HotRestartError.
36    ///
37    /// # Arguments
38    ///
39    /// - `Error` - The source error to convert.
40    ///
41    /// # Returns
42    ///
43    /// - `Self` - The converted error.
44    #[inline(always)]
45    fn from(err: Error) -> Self {
46        HotRestartError::Other(err.to_string())
47    }
48}