Lines Matching defs:T
37 /// Returns `true` if `value` can be represented with at most `N` bits in a `T`.
39 fn fits_within<T: Integer>(value: T, num_bits: u32) -> bool {
40 fits_within!(value, T, num_bits)
53 /// - `N` is less than or equal to `T::BITS`.
230 pub struct Bounded<T: Integer, const N: u32>(T);
274 impl<T, const N: u32> Bounded<T, N>
276 T: Integer,
286 const unsafe fn __new(value: T) -> Self {
291 const_assert!(N <= T::BITS);
327 pub fn try_new(value: T) -> Option<Self> {
366 pub fn from_expr(expr: T) -> Self {
389 pub const fn get(self) -> T {
407 pub const fn extend<const M: u32>(self) -> Bounded<T, M> {
436 pub fn try_shrink<const M: u32>(self) -> Option<Bounded<T, M>> {
437 Bounded::<T, M>::try_new(self.get())
443 /// Both `T` and `U` must be of same signedness, and `U` must be at least as large as
461 U: TryFrom<T> + Integer,
462 T: Integer,
463 U: Integer<Signedness = T::Signedness>,
466 // `U` and `T` have the same sign, hence this conversion cannot fail.
487 pub fn shr<const SHIFT: u32, const RES: u32>(self) -> Bounded<T, RES> {
508 pub fn shl<const SHIFT: u32, const RES: u32>(self) -> Bounded<T, RES> {
517 impl<T, const N: u32> Deref for Bounded<T, N>
519 T: Integer,
521 type Target = T;
550 pub trait TryIntoBounded<T: Integer, const N: u32> {
554 fn try_into_bounded(self) -> Option<Bounded<T, N>>;
558 impl<T, U, const N: u32> TryIntoBounded<T, N> for U
560 T: Integer,
561 U: TryInto<T>,
563 fn try_into_bounded(self) -> Option<Bounded<T, N>> {
570 impl<T, U, const N: u32, const M: u32> PartialEq<Bounded<U, M>> for Bounded<T, N>
572 T: Integer,
574 T: PartialEq<U>,
581 impl<T, const N: u32> Eq for Bounded<T, N> where T: Integer {}
583 impl<T, U, const N: u32, const M: u32> PartialOrd<Bounded<U, M>> for Bounded<T, N>
585 T: Integer,
587 T: PartialOrd<U>,
594 impl<T, const N: u32> Ord for Bounded<T, N>
596 T: Integer,
597 T: Ord,
606 impl<T, const N: u32> PartialEq<T> for Bounded<T, N>
608 T: Integer,
609 T: PartialEq,
611 fn eq(&self, other: &T) -> bool {
616 impl<T, const N: u32> PartialOrd<T> for Bounded<T, N>
618 T: Integer,
619 T: PartialOrd,
621 fn partial_cmp(&self, other: &T) -> Option<cmp::Ordering> {
628 impl<T, const N: u32, const M: u32> ops::Add<Bounded<T, M>> for Bounded<T, N>
630 T: Integer,
631 T: ops::Add<Output = T>,
633 type Output = T;
635 fn add(self, rhs: Bounded<T, M>) -> Self::Output {
640 impl<T, const N: u32, const M: u32> ops::BitAnd<Bounded<T, M>> for Bounded<T, N>
642 T: Integer,
643 T: ops::BitAnd<Output = T>,
645 type Output = T;
647 fn bitand(self, rhs: Bounded<T, M>) -> Self::Output {
652 impl<T, const N: u32, const M: u32> ops::BitOr<Bounded<T, M>> for Bounded<T, N>
654 T: Integer,
655 T: ops::BitOr<Output = T>,
657 type Output = T;
659 fn bitor(self, rhs: Bounded<T, M>) -> Self::Output {
664 impl<T, const N: u32, const M: u32> ops::BitXor<Bounded<T, M>> for Bounded<T, N>
666 T: Integer,
667 T: ops::BitXor<Output = T>,
669 type Output = T;
671 fn bitxor(self, rhs: Bounded<T, M>) -> Self::Output {
676 impl<T, const N: u32, const M: u32> ops::Div<Bounded<T, M>> for Bounded<T, N>
678 T: Integer,
679 T: ops::Div<Output = T>,
681 type Output = T;
683 fn div(self, rhs: Bounded<T, M>) -> Self::Output {
688 impl<T, const N: u32, const M: u32> ops::Mul<Bounded<T, M>> for Bounded<T, N>
690 T: Integer,
691 T: ops::Mul<Output = T>,
693 type Output = T;
695 fn mul(self, rhs: Bounded<T, M>) -> Self::Output {
700 impl<T, const N: u32, const M: u32> ops::Rem<Bounded<T, M>> for Bounded<T, N>
702 T: Integer,
703 T: ops::Rem<Output = T>,
705 type Output = T;
707 fn rem(self, rhs: Bounded<T, M>) -> Self::Output {
712 impl<T, const N: u32, const M: u32> ops::Sub<Bounded<T, M>> for Bounded<T, N>
714 T: Integer,
715 T: ops::Sub<Output = T>,
717 type Output = T;
719 fn sub(self, rhs: Bounded<T, M>) -> Self::Output {
726 impl<T, const N: u32> ops::Add<T> for Bounded<T, N>
728 T: Integer,
729 T: ops::Add<Output = T>,
731 type Output = T;
733 fn add(self, rhs: T) -> Self::Output {
738 impl<T, const N: u32> ops::BitAnd<T> for Bounded<T, N>
740 T: Integer,
741 T: ops::BitAnd<Output = T>,
743 type Output = T;
745 fn bitand(self, rhs: T) -> Self::Output {
750 impl<T, const N: u32> ops::BitOr<T> for Bounded<T, N>
752 T: Integer,
753 T: ops::BitOr<Output = T>,
755 type Output = T;
757 fn bitor(self, rhs: T) -> Self::Output {
762 impl<T, const N: u32> ops::BitXor<T> for Bounded<T, N>
764 T: Integer,
765 T: ops::BitXor<Output = T>,
767 type Output = T;
769 fn bitxor(self, rhs: T) -> Self::Output {
774 impl<T, const N: u32> ops::Div<T> for Bounded<T, N>
776 T: Integer,
777 T: ops::Div<Output = T>,
779 type Output = T;
781 fn div(self, rhs: T) -> Self::Output {
786 impl<T, const N: u32> ops::Mul<T> for Bounded<T, N>
788 T: Integer,
789 T: ops::Mul<Output = T>,
791 type Output = T;
793 fn mul(self, rhs: T) -> Self::Output {
798 impl<T, const N: u32> ops::Neg for Bounded<T, N>
800 T: Integer,
801 T: ops::Neg<Output = T>,
803 type Output = T;
810 impl<T, const N: u32> ops::Not for Bounded<T, N>
812 T: Integer,
813 T: ops::Not<Output = T>,
815 type Output = T;
822 impl<T, const N: u32> ops::Rem<T> for Bounded<T, N>
824 T: Integer,
825 T: ops::Rem<Output = T>,
827 type Output = T;
829 fn rem(self, rhs: T) -> Self::Output {
834 impl<T, const N: u32> ops::Sub<T> for Bounded<T, N>
836 T: Integer,
837 T: ops::Sub<Output = T>,
839 type Output = T;
841 fn sub(self, rhs: T) -> Self::Output {
848 impl<T, const N: u32> fmt::Display for Bounded<T, N>
850 T: Integer,
851 T: fmt::Display,
858 impl<T, const N: u32> fmt::Binary for Bounded<T, N>
860 T: Integer,
861 T: fmt::Binary,
868 impl<T, const N: u32> fmt::LowerExp for Bounded<T, N>
870 T: Integer,
871 T: fmt::LowerExp,
878 impl<T, const N: u32> fmt::LowerHex for Bounded<T, N>
880 T: Integer,
881 T: fmt::LowerHex,
888 impl<T, const N: u32> fmt::Octal for Bounded<T, N>
890 T: Integer,
891 T: fmt::Octal,
898 impl<T, const N: u32> fmt::UpperExp for Bounded<T, N>
900 T: Integer,
901 T: fmt::UpperExp,
908 impl<T, const N: u32> fmt::UpperHex for Bounded<T, N>
910 T: Integer,
911 T: fmt::UpperHex,
924 impl<T> $trait for Bounded<T, $num_bits> where T: Integer {}
945 impl<T> AtLeastXBits<32> for T where T: AtLeastXBits<64> {}
955 impl<T> AtLeastXBits<16> for T where T: AtLeastXBits<32> {}
963 impl<T> AtLeastXBits<8> for T where T: AtLeastXBits<16> {}
982 impl<T, const N: u32> From<$type> for Bounded<T, N>
985 T: Integer<Signedness = <$type as Integer>::Signedness> + From<$type>,
991 unsafe { Self::__new(T::from(value)) }
1019 impl<T> FitsInXBits<16> for T where T: FitsInXBits<8> {}
1024 impl<T> FitsInXBits<32> for T where T: FitsInXBits<16> {}
1032 impl<T> FitsInXBits<64> for T where T: FitsInXBits<32> {}
1058 impl<T, const N: u32> From<Bounded<T, N>> for $type
1060 $type: Integer + TryFrom<T>,
1061 T: Integer<Signedness = <$type as Integer>::Signedness>,
1062 Bounded<T, N>: FitsInXBits<{ <$type as Integer>::BITS as usize }>,
1064 fn from(value: Bounded<T, N>) -> $type {
1082 impl<T> From<Bounded<T, 1>> for bool
1084 T: Integer + Zeroable,
1086 fn from(value: Bounded<T, 1>) -> Self {
1091 impl<T, const N: u32> From<bool> for Bounded<T, N>
1093 T: Integer + From<bool>,
1098 unsafe { Self::__new(T::from(value)) }
1102 impl<T> Bounded<T, 1>
1104 T: Integer + Zeroable,