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 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
16 match self {
17 HotRestartError::CargoWatchNotInstalled => write!(
18 f,
19 "Cargo-watch is not installed. Please install it using: cargo install cargo-watch"
20 ),
21 HotRestartError::CommandSpawnFailed(e) => {
22 write!(f, "Failed to spawn cargo watch command: {e}")
23 }
24 HotRestartError::CommandWaitFailed(e) => {
25 write!(f, "Failed to wait for cargo watch command: {e}")
26 }
27 HotRestartError::Other(e) => write!(f, "An unexpected error occurred: {e}"),
28 }
29 }
30}
31
32/// Implementation of From trait for converting Error to HotRestartError.
33impl From<Error> for HotRestartError {
34 /// Converts a generic Error into HotRestartError.
35 ///
36 /// # Arguments
37 ///
38 /// - `Error` - The source error to convert.
39 ///
40 /// # Returns
41 ///
42 /// - `Self` - The converted error.
43 fn from(err: Error) -> Self {
44 HotRestartError::Other(err.to_string())
45 }
46}