♻️ Error cleanup

This commit is contained in:
François Autin 2023-03-28 19:37:31 +02:00
parent 7f37965ed4
commit 40039eca17
No known key found for this signature in database
GPG Key ID: 343F5D382E1DD77C

View File

@ -14,7 +14,7 @@
//! } //! }
//! ``` //! ```
use std::fmt::{self, Error}; use std::fmt;
/// Machine Error /// Machine Error
/// This error serves as a specific exception handler for the Machine struct /// This error serves as a specific exception handler for the Machine struct
@ -24,23 +24,22 @@ pub struct MachineError {
message: String message: String
} }
impl MachineError { /// This impl allows this MachineError to be formatted into an empty format.
///
/// MachineError constructor /// ```
pub fn new(message: &str) -> MachineError { /// // Result of printing a MachineError
MachineError { /// let m = MachineError::new("Lorem Ipsum");
message: message.to_string() /// println!("Example: {}", m);
} /// ```
} ///
/// Console output:Error}
} /// ```
/// example Lorem Ipsum
/// ```
impl fmt::Display for MachineError { impl fmt::Display for MachineError {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
write!(f, "Machine error: {}", &self.message) write!(f, "Machine error: {}", &self.message)
} }
} }
impl From<&str> for MachineError { impl From<&str> for MachineError {