Add CastFrom as a convenience form of CastInto
This commit is contained in:
parent
ba01751407
commit
bac7b1e777
1 changed files with 10 additions and 0 deletions
|
|
@ -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 {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue