Search code examples
rustprimitive

How to get min and max value of primitives?


How can I store the minimum value of i32 in a variable?

// Java Example :
int min = Integer.MIN_VALUE;
// C++ example
int min = INT_MIN;

I want to do something like:

let min: i32 = i32_MIN_VALUE;

Solution

  • You have some const defined:

    let min: u32 = u32::MIN;
    

    They are also defined for other primitive numeric types.