diff options
| author | Jacob Pratt <jacob@jhpratt.dev> | 2022-08-10 18:19:07 -0400 |
|---|---|---|
| committer | Jacob Pratt <jacob@jhpratt.dev> | 2022-12-15 03:55:21 +0000 |
| commit | b134d1108ffc92bfb5081d31e5e41141f918e942 (patch) | |
| tree | 4664f931522ab284f9347de4f90549d9489a07d4 | |
| parent | 16990de53e553bbe1199c6b0a375772f15799414 (diff) | |
| download | rust-b134d1108ffc92bfb5081d31e5e41141f918e942.tar.gz rust-b134d1108ffc92bfb5081d31e5e41141f918e942.zip | |
Implement `From<bool>` for f32, f64
| -rw-r--r-- | library/core/src/convert/num.rs | 20 |
1 files changed, 20 insertions, 0 deletions
diff --git a/library/core/src/convert/num.rs b/library/core/src/convert/num.rs index 9c0d7e9a1e8..45e2f711c6c 100644 --- a/library/core/src/convert/num.rs +++ b/library/core/src/convert/num.rs @@ -168,6 +168,26 @@ impl_from! { u32, f64, #[stable(feature = "lossless_float_conv", since = "1.6.0" // Float -> Float impl_from! { f32, f64, #[stable(feature = "lossless_float_conv", since = "1.6.0")] } +// bool -> Float +#[stable(feature = "float_from_bool", since = "CURRENT_RUSTC_VERSION")] +#[rustc_const_unstable(feature = "const_num_from_num", issue = "87852")] +impl const From<bool> for f32 { + /// Converts `bool` to `f32` losslessly. + #[inline] + fn from(small: bool) -> Self { + small as u8 as Self + } +} +#[stable(feature = "float_from_bool", since = "CURRENT_RUSTC_VERSION")] +#[rustc_const_unstable(feature = "const_num_from_num", issue = "87852")] +impl const From<bool> for f64 { + /// Converts `bool` to `f64` losslessly. + #[inline] + fn from(small: bool) -> Self { + small as u8 as Self + } +} + // no possible bounds violation macro_rules! try_from_unbounded { ($source:ty, $($target:ty),*) => {$( |
