Skip to content

Conversation

@linclelinkpart5
Copy link

Adds functionality as requested in #252.

This is done by adding ConstLowerBounded and ConstUpperBounded traits, with associated costs of const MIN: Self and const MAX: Self, respectively. In addition, I also included ConstBounded as a supertrait, and impl'd it for all types that implement ConstLowerBounded + ConstUpperBounded:

pub trait ConstBounded: ConstLowerBounded + ConstUpperBounded {}

impl<T: ConstLowerBounded + ConstUpperBounded> ConstBounded for T {}

These traits have been implemented for all primitive types that the existing Bounded traits have been impl'd for.

@apps4uco
Copy link

apps4uco commented Dec 7, 2025

Hope you don't mind a nitpicking suggestion, the macro can be simplified:

macro_rules! const_bounded_impl {
    ($t:ty) => {
        impl ConstLowerBounded for $t {
            const MIN: Self = Self::MIN;
        }

        impl ConstUpperBounded for $t {
            const MAX: Self = Self::MAX;
        }
    };
}

const_bounded_impl!(usize);
const_bounded_impl!(u8);
const_bounded_impl!(u16);
const_bounded_impl!(u32);
const_bounded_impl!(u64);
const_bounded_impl!(u128);

const_bounded_impl!(isize);
const_bounded_impl!(i8);
const_bounded_impl!(i16);
const_bounded_impl!(i32);
const_bounded_impl!(i64);
const_bounded_impl!(i128);

const_bounded_impl!(f32);
const_bounded_impl!(f64);

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants