async_ecs/misc/
try_default.rs

1pub trait TryDefault: Sized {
2    fn try_default() -> Result<Self, String>;
3
4    fn unwrap_default() -> Self {
5        match Self::try_default() {
6            Ok(x) => x,
7            Err(e) => panic!("Failed to create a default value for storage ({:?})", e),
8        }
9    }
10}
11
12impl<T> TryDefault for T
13where
14    T: Default,
15{
16    fn try_default() -> Result<Self, String> {
17        Ok(T::default())
18    }
19}