panda/
init_return.rs

1/// A trait representing types that can be used as the return value for a `#[panda::init]`
2/// function
3pub trait InitReturn {
4    fn into_init_bool(self) -> bool;
5}
6
7impl InitReturn for bool {
8    fn into_init_bool(self) -> bool {
9        self
10    }
11}
12
13impl InitReturn for () {
14    fn into_init_bool(self) -> bool {
15        true
16    }
17}
18
19impl InitReturn for i32 {
20    fn into_init_bool(self) -> bool {
21        self == 0
22    }
23}
24
25impl<I: InitReturn, E: core::fmt::Debug> InitReturn for Result<I, E> {
26    fn into_init_bool(self) -> bool {
27        match self {
28            Ok(x) => x.into_init_bool(),
29            Err(err) => {
30                eprintln!("Error initializing plugin: {:?}", err);
31
32                false
33            }
34        }
35    }
36}