From bac7b1e77718fea6649ce3f88dc1fd7e628508e9 Mon Sep 17 00:00:00 2001 From: Trevor Gross Date: Fri, 17 May 2024 22:02:37 -0500 Subject: [PATCH] Add `CastFrom` as a convenience form of `CastInto` --- library/compiler-builtins/src/int/mod.rs | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/library/compiler-builtins/src/int/mod.rs b/library/compiler-builtins/src/int/mod.rs index 2b6d4b812ee0..0c67a4c16566 100644 --- a/library/compiler-builtins/src/int/mod.rs +++ b/library/compiler-builtins/src/int/mod.rs @@ -380,6 +380,16 @@ public_test_dep! { pub(crate) trait CastInto: Copy { fn cast(self) -> T; } + +pub(crate) trait CastFrom:Copy { + fn cast_from(value: T) -> Self; +} +} + +impl + Copy> CastFrom for T { + fn cast_from(value: U) -> Self { + value.cast() + } } macro_rules! cast_into {