All integer types in Rust, signed and unsigned, have their maximum value. We can get this value for any integer type with the MAX
constant.
type::MAX
type
: This represents any integer datatypes, such as u32
, u8
, i64
, and so on.
fn main() {println!("{}", u8::MAX);println!("{}", u16::MAX);println!("{}", u32::MAX);println!("{}", u64::MAX);println!("{}", u128::MAX);println!("{}", i8::MAX);println!("{}", i16::MAX);println!("{}", i32::MAX);println!("{}", i64::MAX);println!("{}", i128::MAX);}
MAX
method to get the largest value representable by an integer datatype. Next, we print the result to the console.RELATED TAGS
CONTRIBUTOR