2022-12-21 16:36:30 +01:00
|
|
|
# Scalar Types
|
|
|
|
|
|
|
|
| | Types | Literals |
|
|
|
|
|------------------------|--------------------------------------------|-------------------------------|
|
|
|
|
| Signed integers | `i8`, `i16`, `i32`, `i64`, `i128`, `isize` | `-10`, `0`, `1_000`, `123i64` |
|
|
|
|
| Unsigned integers | `u8`, `u16`, `u32`, `u64`, `u128`, `usize` | `0`, `123`, `10u16` |
|
|
|
|
| Floating point numbers | `f32`, `f64` | `3.14`, `-10.0e20`, `2f32` |
|
|
|
|
| Strings | `&str` | `"foo"`, `r#"\\"#` |
|
|
|
|
| Unicode scalar values | `char` | `'a'`, `'α'`, `'∞'` |
|
2022-12-26 19:35:09 -08:00
|
|
|
| Byte strings | `&[u8]` | `b"abc"`, `br#" " "#` |
|
2022-12-21 16:36:30 +01:00
|
|
|
| Booleans | `bool` | `true`, `false` |
|
|
|
|
|
|
|
|
The types have widths as follows:
|
|
|
|
|
2022-12-26 19:35:09 -08:00
|
|
|
* `iN`, `uN`, and `fN` are _N_ bits wide,
|
2022-12-21 16:36:30 +01:00
|
|
|
* `isize` and `usize` are the width of a pointer,
|
|
|
|
* `char` is 32 bit wide,
|
|
|
|
* `bool` is 8 bit wide.
|