Rust datatypes: Difference between revisions

From wikinotes
Line 27: Line 27:
* signed integers are positive, and use all available bits
* signed integers are positive, and use all available bits
* unsigned integers range is split in two, can be positive/negative
* unsigned integers range is split in two, can be positive/negative
 
* 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

Revision as of 22:32, 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 are positive, and use all available bits
  • unsigned integers range is split in two, can be positive/negative
  • use radix to calculate max size that can be accomodated with b bits
// signed integers, by bit-size
i8
i16
i32
i64
i128
isize

// unsigned integers, by bit-size
u8
u16
u36
u64
u128
usize

Floating Point

Boolean

true
false

Collections

tuples

arrays