♻️ Implement From<&str> and From<String> traits to MachineError, and simplified opiw_instruction

This commit is contained in:
François Autin
2023-03-27 15:56:23 +02:00
parent 2162232199
commit 7f37965ed4
2 changed files with 25 additions and 25 deletions

View File

@ -14,7 +14,7 @@
//! }
//! ```
use std::fmt;
use std::fmt::{self, Error};
/// Machine Error
/// This error serves as a specific exception handler for the Machine struct
@ -41,4 +41,16 @@ impl fmt::Display for MachineError {
write!(f, "Machine error: {}", &self.message)
}
}
impl From<&str> for MachineError {
fn from(value: &str) -> Self {
MachineError { message: value.to_string() }
}
}
impl From<String> for MachineError {
fn from(value: String) -> Self {
MachineError { message: value }
}
}