// Copyright © 2018–2025 Trevor Spiteri // This library is free software: you can redistribute it and/or // modify it under the terms of either // // * the Apache License, Version 2.0 or // * the MIT License // // at your option. // // You should have recieved copies of the Apache License and the MIT // License along with the library. If not, see // and // . use crate::types::extra::{LeEqU8, LeEqU16, LeEqU32, LeEqU64, LeEqU128}; use crate::{ FixedI8, FixedI16, FixedI32, FixedI64, FixedI128, FixedU8, FixedU16, FixedU32, FixedU64, FixedU128, Unwrapped, Wrapping, }; use bytemuck::{Contiguous, Pod, TransparentWrapper, Zeroable}; macro_rules! unsafe_impl_traits { ($Fixed:ident, $LeEqU:ident, $Inner:ident) => { unsafe impl Zeroable for $Fixed {} unsafe impl Pod for $Fixed {} unsafe impl Contiguous for $Fixed { type Int = $Inner; const MAX_VALUE: $Inner = $Inner::MAX; const MIN_VALUE: $Inner = $Inner::MIN; } unsafe impl TransparentWrapper<$Inner> for $Fixed {} unsafe impl Zeroable for Wrapping<$Fixed> {} unsafe impl Pod for Wrapping<$Fixed> {} unsafe impl Contiguous for Wrapping<$Fixed> { type Int = $Inner; const MAX_VALUE: $Inner = $Inner::MAX; const MIN_VALUE: $Inner = $Inner::MIN; } unsafe impl TransparentWrapper<$Fixed> for Wrapping<$Fixed> {} unsafe impl Zeroable for Unwrapped<$Fixed> {} unsafe impl Pod for Unwrapped<$Fixed> {} unsafe impl Contiguous for Unwrapped<$Fixed> { type Int = $Inner; const MAX_VALUE: $Inner = $Inner::MAX; const MIN_VALUE: $Inner = $Inner::MIN; } unsafe impl TransparentWrapper<$Fixed> for Unwrapped<$Fixed> {} }; } // SAFETY: all fixed-point numbers are repr(transparent) over primitive integer // types which are both Pod and Zeroable, and Wrapping and Unwrapped are both // repr(transparent) over fixed-point numbers. unsafe_impl_traits! { FixedI8, LeEqU8, i8 } unsafe_impl_traits! { FixedI16, LeEqU16, i16 } unsafe_impl_traits! { FixedI32, LeEqU32, i32 } unsafe_impl_traits! { FixedI64, LeEqU64, i64 } unsafe_impl_traits! { FixedI128, LeEqU128, i128 } unsafe_impl_traits! { FixedU8, LeEqU8, u8 } unsafe_impl_traits! { FixedU16, LeEqU16, u16 } unsafe_impl_traits! { FixedU32, LeEqU32, u32 } unsafe_impl_traits! { FixedU64, LeEqU64, u64 } unsafe_impl_traits! { FixedU128, LeEqU128, u128 }