Add CastFrom as a convenience form of CastInto

This commit is contained in:
Trevor Gross 2024-05-17 22:02:37 -05:00 committed by Trevor Gross
parent ba01751407
commit bac7b1e777

View file

@ -380,6 +380,16 @@ public_test_dep! {
pub(crate) trait CastInto<T: Copy>: Copy {
fn cast(self) -> T;
}
pub(crate) trait CastFrom<T: Copy>:Copy {
fn cast_from(value: T) -> Self;
}
}
impl<T: Copy, U: CastInto<T> + Copy> CastFrom<U> for T {
fn cast_from(value: U) -> Self {
value.cast()
}
}
macro_rules! cast_into {