From 40039eca173132fb6a9da80d48ae54d81dfd9d8d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fran=C3=A7ois=20Autin?= Date: Tue, 28 Mar 2023 19:37:31 +0200 Subject: [PATCH] :recycle: Error cleanup --- src/simulator/error.rs | 27 +++++++++++++-------------- 1 file changed, 13 insertions(+), 14 deletions(-) diff --git a/src/simulator/error.rs b/src/simulator/error.rs index 6b7c515..d6ea783 100644 --- a/src/simulator/error.rs +++ b/src/simulator/error.rs @@ -14,7 +14,7 @@ //! } //! ``` -use std::fmt::{self, Error}; +use std::fmt; /// Machine Error /// This error serves as a specific exception handler for the Machine struct @@ -24,23 +24,22 @@ pub struct MachineError { message: String } -impl MachineError { - - /// MachineError constructor - pub fn new(message: &str) -> MachineError { - MachineError { - message: message.to_string() - } - } - -} - +/// This impl allows this MachineError to be formatted into an empty format. +/// +/// ``` +/// // Result of printing a MachineError +/// let m = MachineError::new("Lorem Ipsum"); +/// println!("Example: {}", m); +/// ``` +/// +/// Console output:Error} +/// ``` +/// example Lorem Ipsum +/// ``` impl fmt::Display for MachineError { - fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { write!(f, "Machine error: {}", &self.message) } - } impl From<&str> for MachineError {