use std::{fmt::Debug, str::FromStr};
pub trait MustParse {
fn must_parse<T: FromStr>(&self) -> T
where
<T as FromStr>::Err: Debug;
}
impl MustParse for &str {
fn must_parse<T: FromStr>(&self) -> T
where
<T as FromStr>::Err: Debug,
{
self.parse()
.unwrap_or_else(|_| panic!("Failed to parse: {self}"))
}
}
impl MustParse for String {
fn must_parse<T: FromStr>(&self) -> T
where
<T as FromStr>::Err: Debug,
{
self.as_str().must_parse()
}
}