Rust datatypes: Difference between revisions
From wikinotes
Line 25: | Line 25: | ||
=== Integers === | === Integers === | ||
<blockquote> | <blockquote> | ||
* signed | * signed integers range is split in two, can be positive/negative | ||
* unsigned integers are positive, and use all available bits | |||
* use [[radix]] to calculate max size that can be accomodated with ''b'' bits <math>2^b</math> | * use [[radix]] to calculate max size that can be accomodated with ''b'' bits <math>2^b</math> | ||
<syntaxhighlight lang="rust"> | <syntaxhighlight lang="rust"> | ||
// signed integers, by bit-size | // signed integers, by bit-size | ||
i8 | i8 // -128..127 | ||
i16 | i16 // -32768..32767 | ||
i32 | i32 // -2147483648..2147483647 | ||
i64 | i64 // ... | ||
i128 | i128 | ||
isize | isize | ||
// unsigned integers, by bit-size | // unsigned integers, by bit-size | ||
u8 | u8 // 0..255 | ||
u16 | u16 // 0..65535 | ||
u36 | u36 // 0..4294967295 | ||
u64 | u64 // ... | ||
u128 | u128 | ||
usize | usize |
Revision as of 23:18, 29 August 2021
Primitives
Text
char
char
Numbers
implied type let var = 12;
assigned type let var: i8 = 12;
type suffix let var = 12i8;
Integers
- signed integers range is split in two, can be positive/negative
- unsigned integers are positive, and use all available bits
- use radix to calculate max size that can be accomodated with b bits
// signed integers, by bit-size i8 // -128..127 i16 // -32768..32767 i32 // -2147483648..2147483647 i64 // ... i128 isize // unsigned integers, by bit-size u8 // 0..255 u16 // 0..65535 u36 // 0..4294967295 u64 // ... u128 usizeFloating Point
Boolean
true false
Collections
tuples
arrays