Rust Data Types
Data types in Rust are specified or identified as the data storage format that tells the compiler or interpreter how the programmer enters the data and what type of data they enter into the program. Data types are used to define a variable before use in a program. Data types determine the size of the variable, space it occupies in storage.
Data types are divided into following three categories:
- Primitive Data Types
- Derived Data Types
- User Defined Data Types
Integer Types
Integer Types
Type | Sign | Length(bit) | Value |
i8 | Signed | 8 | -128 to 128 |
u8 | Unsigned | 8 | 0 to 256 |
i16 | Signed | 16 | -32.768 to 32.768 |
u16 | Unsigned | 16 | 0 to 65.535 |
i32 | Signed | 32 | -2.147.483.648 to 2.147.483.648 |
u32 | Unsigned | 32 | 0 to 4.294.967.295 |
i64 | Signed | 64 | -9,223.372.036.854.775.808 to 9,223.372.036.854.775.808 |
u64 | Unsigned | 64 | 0 to 18.446.744.073.709.551.615 |
i128 | Signed | 128 | -170.141.183,460.469,231.731.687.303.715.884.105.728 to 170.141.183,460.469,231.731.687.303.715.884.105.728 |
u128 | Unsigned | 128 | 0 to 340.282.366.920.938.463.463.374.607.431.768.211.455 |
isize | Signed | arch | Depends on architecture (32/64-bit) |
usize | Unsigned | arch | Depends on architecture (32/64-bit) |
Floating-Point Types
Type | Value | Absolute minimum (non-zero) |
f32 | ±1,175494351e-38 to ±3,402823466e+38 | 1,401298464e-45 |
f64 | ±2.2250738585072014e-308 to ±1.7976931348623157e+308 | 4.9406564584124654e-324 |
Boolean Type
Boolean type in Rust has two possible values: true and false.
Booleans are one byte in size.
The Boolean type in Rust is specified using bool.
Character Type
Rust’s char type is the language’s most primitive alphabetic type.
Tuple Type
Array Type