1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
use std::fmt::Display;
use colored::Colorize;
use crate::{
rail_machine::{RailRunResult, RailState, RailVal},
RunConventions,
};
pub fn info(conv: &RunConventions, thing: impl Display) {
eprintln!("{}{}", conv.info_prefix, thing.to_string().dimmed().red());
}
pub fn warn(conv: &RunConventions, thing: impl Display) {
eprintln!("{}{}", conv.warn_prefix, thing.to_string().dimmed().red());
}
pub fn warn_coerce(result: RailRunResult) -> RailState {
match result {
Ok(state) => state,
Err((state, err)) => {
warn(state.conventions, format!("{:?}", err));
state
}
}
}
pub fn error(conv: &RunConventions, thing: impl Display) {
eprintln!("{}{}", conv.error_prefix, thing.to_string().dimmed().red());
}
pub fn error_coerce(result: RailRunResult) -> RailState {
match result {
Ok(state) => state,
Err((state, err)) => {
error(state.conventions, format!("{:?}", err));
state
}
}
}
pub fn fatal(conv: &RunConventions, thing: impl Display) {
eprintln!("{}{}", conv.fatal_prefix, thing.to_string().dimmed().red());
}
pub fn type_panic_msg(context: &str, expected: &str, actual: RailVal) -> String {
format!(
"[Context: {}] Wanted {}, but got {}",
context, expected, actual
)
}