1#[cfg(any(feature = "native", feature = "wasm"))]
9use better_logger::logger;
10#[cfg(any(feature = "native", feature = "wasm"))]
11use std::fmt::Debug;
12#[cfg(any(feature = "native", feature = "wasm"))]
13use std::panic::Location;
14#[cfg(any(feature = "native", feature = "wasm"))]
15use std::any::type_name;
16
17#[cfg(any(feature = "native", feature = "wasm"))]
29#[track_caller]
30pub fn log_assert_eq<G>(left: &G, right: &G)
31where
32 G: PartialEq + Debug,
33{
34 if !(left == right) {
35 let location = Location::caller();
36 let type_of_g = type_name::<G>();
37 logger::error!(r#"Assertion Failed: left "{:?}" != right "{:?}" (Location: {}:{}:{}) (Type: {})"#, left, right, location.file(), location.line(), location.column(), type_of_g);
38 panic!(r#"Assertion Failed: left "{:?}" != right "{:?}" (Location: {}:{}:{}) (Type: {})"#, left, right, location.file(), location.line(), location.column(), type_of_g);
39 }
40}
41
42#[cfg(any(feature = "native", feature = "wasm"))]
43#[track_caller]
44pub fn log_assert_ne<G>(left: &G, right: &G)
45where
46 G: PartialEq + Debug,
47{
48 if !(left != right) {
49 let location = Location::caller();
50 let type_of_g = type_name::<G>();
51 logger::error!(r#"Assertion Failed: left "{:?}" == right "{:?}" (Location: {}:{}:{}) (Type: {})"#, left, right, location.file(), location.line(), location.column(), type_of_g);
52 panic!(r#"Assertion Failed: left "{:?}" == right "{:?}" (Location: {}:{}:{}) (Type: {})"#, left, right, location.file(), location.line(), location.column(), type_of_g);
53 }
54}
55
56#[cfg(any(feature = "native", feature = "wasm"))]
68#[cfg(debug_assertions)]
69#[track_caller]
70pub fn debug_log_assert_eq<G>(left: &G, right: &G)
71where
72 G: PartialEq + Debug,
73{
74 if !(left == right) {
75 let location = Location::caller();
76 let type_of_g = type_name::<G>();
77 logger::error!(r#"Assertion Failed: left "{:?}" != right "{:?}" (Location: {}:{}:{}) (Type: {})"#, left, right, location.file(), location.line(), location.column(), type_of_g);
78 panic!(r#"Assertion Failed: left "{:?}" != right "{:?}" (Location: {}:{}:{}) (Type: {})"#, left, right, location.file(), location.line(), location.column(), type_of_g);
79 }
80}
81
82#[cfg(any(feature = "native", feature = "wasm"))]
83#[cfg(not(debug_assertions))]
84#[track_caller]
85pub fn debug_log_assert_eq<G>(_left: &G, _right: &G)
86where
87 G: PartialEq + Debug,
88{
89
90}
91
92#[cfg(any(feature = "native", feature = "wasm"))]
93#[cfg(debug_assertions)]
94#[track_caller]
95pub fn debug_log_assert_ne<G>(left: &G, right: &G)
96where
97 G: PartialEq + Debug,
98{
99 if !(left != right) {
100 let location = Location::caller();
101 let type_of_g = type_name::<G>();
102 logger::error!(r#"Assertion Failed: left "{:?}" == right "{:?}" (Location: {}:{}:{}) (Type: {})"#, left, right, location.file(), location.line(), location.column(), type_of_g);
103 panic!(r#"Assertion Failed: left "{:?}" == right "{:?}" (Location: {}:{}:{}) (Type: {})"#, left, right, location.file(), location.line(), location.column(), type_of_g);
104 }
105}
106
107#[cfg(any(feature = "native", feature = "wasm"))]
108#[cfg(not(debug_assertions))]
109#[track_caller]
110pub fn debug_log_assert_ne<G>(_left: &G, _right: &G)
111where
112 G: PartialEq + Debug,
113{
114
115}
116
117#[cfg(any(feature = "native", feature = "wasm"))]
129#[track_caller]
130pub fn log_panic() {
131 let location = Location::caller();
132 logger::error!(r#"Panic (Location: {}:{}:{})"#, location.file(), location.line(), location.column());
133 panic!(r#"Panic (Location: {}:{}:{})"#, location.file(), location.line(), location.column());
134}