diff --git a/src/lib.rs b/src/lib.rs index 9c0c9f2..13ef239 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -539,6 +539,10 @@ impl F16 { } } +trait SameSized {} + +impl SameSized for U where Check<{ mem::size_of::() == mem::size_of::() }>: True {} + /// Mutual transmutation /// /// This trait provides an interface of mutual raw transmutation. The methods @@ -547,12 +551,7 @@ impl F16 { /// /// In this crate, all [`F8`] types implement `Transmute`, and all [`F16`] /// types implement `Transmute`. -pub trait Transmute: Copy { - /// Assert the same size between `T` and `Self` - /// - /// Do not override this constant. - const _SAME_SIZE: () = assert!(mem::size_of::() == mem::size_of::()); - +pub trait Transmute: Copy + SameSized { /// Raw transmutation from `T` fn from_bits(v: T) -> Self { unsafe { mem::transmute_copy(&v) } @@ -567,6 +566,7 @@ pub trait Transmute: Copy { impl Transmute for F8 where Check<{ Self::VALID }>: True, + Self: SameSized, { fn from_bits(v: u8) -> Self { Self::from_bits(v) @@ -580,6 +580,7 @@ where impl Transmute for F16 where Check<{ Self::VALID }>: True, + Self: SameSized, { fn from_bits(v: u16) -> Self { Self::from_bits(v)