Data types in Rust
Rust is a [[statically typed language]] - the [[compiler]] must know the [[data type]] of each [[variable]]. The compiler can usually infer what type we want to use based on the value and how we use it.
We need to define type of variable in cases when many types are possible, such as when we are converting a [[String]] to a [[numeric type]].
In rust there are 2 types of data types: - [[Scalar]] - represents a single value (1, 9.4, 'c') - [[Integer]]
Length | Signed | Unsigned |
---|---|---|
8-bit | `i8` | `u8` |
16-bit | `i16` | `u16` |
32-bit | `i32` | `u32` |
64-bit | `i64` | `u64` |
128-bit | `i128` | `u128` |
arch | `isize` | `usize` |
- Floating-point number
- [[Boolean]]
- [[Character]]
- Enclosed with single quotes.
- [[Compound]]
ffn main() {
let a:i128 = -1;
let b:u8 = 1;
let c:f32=132.0048;
let d:bool = true;
let e:char = 'c';
println!(" {} {} {} {} {}", a, b, c, d, e);
}
davis@davis-arch ~/projects/rust ./datatypes
-1 1 132.0048 true c