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 ($($arg:tt)+) => {
26 Err($crate::types::SimError(format!($($arg)+).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 ReadRequest,
50 WriteRequest,
51 WriteNonPostedRequest,
52 ReadResponse,
53 WriteNonPostedResponse,
54 Control,
55}
56
57impl fmt::Display for AccessType {
58 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
59 match self {
60 AccessType::ReadRequest => {
61 write!(f, "ReadRequest")
62 }
63 AccessType::WriteRequest => {
64 write!(f, "WriteRequest")
65 }
66 AccessType::WriteNonPostedRequest => {
67 write!(f, "WriteNonPostedRequest")
68 }
69 AccessType::ReadResponse => {
70 write!(f, "ReadResponse")
71 }
72 AccessType::WriteNonPostedResponse => {
73 write!(f, "WriteNonPostedResponse")
74 }
75 AccessType::Control => {
76 write!(f, "Control")
77 }
78 }
79 }
80}