cairo_lang_utils/
casts.rs

1pub trait IntoOrPanic: Sized + Copy + core::fmt::Debug {
2    fn into_or_panic<T>(self) -> T
3    where
4        T: TryFrom<Self> + core::fmt::Debug,
5        <T as TryFrom<Self>>::Error: core::fmt::Debug,
6    {
7        let as_opt: Result<T, _> = self.try_into();
8        as_opt.unwrap_or_else(|_| panic!("Failed to cast from {self:?}."))
9    }
10}
11
12impl IntoOrPanic for i16 {}
13impl IntoOrPanic for u16 {}
14impl IntoOrPanic for i32 {}
15impl IntoOrPanic for u32 {}
16impl IntoOrPanic for i64 {}
17impl IntoOrPanic for u64 {}
18impl IntoOrPanic for isize {}
19impl IntoOrPanic for usize {}