diff options
| author | Caleb Zulawski <caleb.zulawski@gmail.com> | 2021-09-22 23:00:59 +0000 |
|---|---|---|
| committer | Jubilee <46493976+workingjubilee@users.noreply.github.com> | 2021-10-22 00:10:44 -0700 |
| commit | 7c2d295a76fcbc6d4c438c5f324903265ee77c94 (patch) | |
| tree | 82741cb2ec03030fce1afdf9ba820821612c5484 | |
| parent | ab8eec7cbabdefdab319d90cc8b0eca61fc7f3dd (diff) | |
| download | rust-7c2d295a76fcbc6d4c438c5f324903265ee77c94.tar.gz rust-7c2d295a76fcbc6d4c438c5f324903265ee77c94.zip | |
Hide mask impl details in sealed trait.
| -rw-r--r-- | crates/core_simd/src/masks.rs | 38 |
1 files changed, 25 insertions, 13 deletions
diff --git a/crates/core_simd/src/masks.rs b/crates/core_simd/src/masks.rs index 1b1677330fb..d460da0d04f 100644 --- a/crates/core_simd/src/masks.rs +++ b/crates/core_simd/src/masks.rs @@ -16,26 +16,36 @@ use crate::simd::{LaneCount, Simd, SimdElement, SupportedLaneCount}; use core::cmp::Ordering; use core::fmt; -/// Marker trait for types that may be used as SIMD mask elements. -pub unsafe trait MaskElement: SimdElement { - #[doc(hidden)] - fn valid<const LANES: usize>(values: Simd<Self, LANES>) -> bool - where - LaneCount<LANES>: SupportedLaneCount; +mod sealed { + use super::*; + + /// Not only does this seal the `MaskElement` trait, but these functions prevent other traits + /// from bleeding into the parent bounds. + /// + /// For example, `eq` could be provided by requiring `MaskElement: PartialEq`, but that would + /// prevent us from ever removing that bound, or from implementing `MaskElement` on + /// non-`PartialEq` types in the future. + pub trait Sealed { + fn valid<const LANES: usize>(values: Simd<Self, LANES>) -> bool + where + LaneCount<LANES>: SupportedLaneCount, + Self: SimdElement; - #[doc(hidden)] - fn eq(self, other: Self) -> bool; + fn eq(self, other: Self) -> bool; - #[doc(hidden)] - const TRUE: Self; + const TRUE: Self; - #[doc(hidden)] - const FALSE: Self; + const FALSE: Self; + } } +use sealed::Sealed; + +/// Marker trait for types that may be used as SIMD mask elements. +pub unsafe trait MaskElement: SimdElement + Sealed {} macro_rules! impl_element { { $ty:ty } => { - unsafe impl MaskElement for $ty { + impl Sealed for $ty { fn valid<const LANES: usize>(value: Simd<Self, LANES>) -> bool where LaneCount<LANES>: SupportedLaneCount, @@ -48,6 +58,8 @@ macro_rules! impl_element { const TRUE: Self = -1; const FALSE: Self = 0; } + + unsafe impl MaskElement for $ty {} } } |
