1use std::error::Error;
6use std::fmt;
7use std::rc::Rc;
8
9use crate::traits::{Event, Runnable};
10
11pub type EventResult<T> = T;
13
14pub type Eventable<T> = Box<dyn Event<T> + 'static>;
15
16pub type Component = Rc<dyn Runnable + 'static>;
19
20#[macro_export]
23macro_rules! sim_error {
25 ($msg:expr) => {
26 Err($crate::types::SimError($msg.to_string()))
27 };
28}
29
30#[derive(Debug)]
32pub struct SimError(pub String);
33
34impl fmt::Display for SimError {
35 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
36 write!(f, "Error: {}", self.0)
37 }
38}
39
40impl Error for SimError {}
41
42pub type SimResult = Result<(), SimError>;
44
45#[derive(Copy, Clone, Debug, Default, PartialEq)]
47pub enum AccessType {
48 #[default]
49 Read,
50 Write,
51 WriteNonPosted,
52 Control,
53}
54
55impl fmt::Display for AccessType {
56 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
57 match self {
58 AccessType::Read => {
59 write!(f, "Read")
60 }
61 AccessType::Write => {
62 write!(f, "Write")
63 }
64 AccessType::WriteNonPosted => {
65 write!(f, "WriteNonPosted")
66 }
67 AccessType::Control => {
68 write!(f, "Control")
69 }
70 }
71 }
72}