Skip to content

Commit f4c8ec4

Browse files
committed
Add CastFrom as a convenience form of CastInto
1 parent fa0f7e0 commit f4c8ec4

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

src/int/mod.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -380,6 +380,16 @@ public_test_dep! {
380380
pub(crate) trait CastInto<T: Copy>: Copy {
381381
fn cast(self) -> T;
382382
}
383+
384+
pub(crate) trait CastFrom<T: Copy>:Copy {
385+
fn cast_from(value: T) -> Self;
386+
}
387+
}
388+
389+
impl<T: Copy, U: CastInto<T> + Copy> CastFrom<U> for T {
390+
fn cast_from(value: U) -> Self {
391+
value.cast()
392+
}
383393
}
384394

385395
macro_rules! cast_into {

0 commit comments

Comments
 (0)