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
pub trait DebuglessUnwrap {
	type Unwrapped;
	fn debugless_unwrap(self) -> Self::Unwrapped;
}

impl<T, E> DebuglessUnwrap for Result<T, E> {
	type Unwrapped = T;
	fn debugless_unwrap(self) -> Self::Unwrapped {
		match self {
			Ok(unwrapped) => unwrapped,
			Err(_) => panic!("Tried to debugless_unwrap Err value"),
		}
	}
}

impl<T> DebuglessUnwrap for Option<T> {
	type Unwrapped = T;
	fn debugless_unwrap(self) -> Self::Unwrapped {
		match self {
			Some(unwrapped) => unwrapped,
			None => panic!("Tried to debugless_unwrap None value"),
		}
	}
}

pub trait DebuglessUnwrapErr {
	type Unwrapped;
	fn debugless_unwrap_err(self) -> Self::Unwrapped;
}

impl<T, E> DebuglessUnwrapErr for Result<T, E> {
	type Unwrapped = E;
	fn debugless_unwrap_err(self) -> Self::Unwrapped {
		match self {
			Ok(_) => panic!("Tried to debugless_unwrap_err Ok value"),
			Err(unwrapped) => unwrapped,
		}
	}
}

pub trait DebuglessUnwrapNone {
	fn debugless_unwrap_none(self);
}

impl<T> DebuglessUnwrapNone for Option<T> {
	fn debugless_unwrap_none(self) {
		if self.is_some() {
			panic!("Tried to debugless_unwrap_none Some value")
		}
	}
}