android_logcat/
expect_log.rs1use std::fmt::Debug;
2
3use crate::logcat::Log;
4
5pub trait ExpectLogcat<T> {
6 fn expect_log(self, msg: &str) -> T;
10}
11
12impl<T, E: Debug> ExpectLogcat<T> for Result<T, E> {
14 fn expect_log(self, msg: &str) -> T {
15 match self {
16 Ok(v) => v,
17 Err(e) => {
18 Log::e(&format!("{}: {:?}", msg, e));
19 panic!("{}: {:?}", msg, e);
20 }
21 }
22 }
23}
24
25impl<T> ExpectLogcat<T> for Option<T> {
27 fn expect_log(self, msg: &str) -> T {
28 match self {
29 Some(v) => v,
30 None => {
31 Log::e(msg);
32 panic!("{}", msg);
33 }
34 }
35 }
36}