1use colored::Colorize;
2
3pub trait BeautifulErrors<T> {
4 fn expect_or_err(self, msg: &str) -> T;
5}
6
7impl<T> BeautifulErrors<T> for Option<T> {
8 fn expect_or_err(self, msg: &str) -> T {
9 match self {
10 Some(val) => val,
11 None => {
12 println!("{}", msg.red().bold());
13 std::process::abort();
14 }
15 }
16 }
17}
18
19impl<T, E> BeautifulErrors<T> for Result<T, E> {
20 fn expect_or_err(self, msg: &str) -> T {
21 match self {
22 Ok(val) => val,
23 Err(_) => {
24 println!("{}", msg.red().bold());
25 std::process::abort();
26 }
27 }
28 }
29}
30
31pub fn panic_err(msg: &str) -> ! {
32 println!("{}", msg.red().bold());
33 std::process::abort();
34}