Rust datatypes: Difference between revisions
From wikinotes
(→tuples) |
|||
Line 92: | Line 92: | ||
== tuples == | == tuples == | ||
<blockquote> | <blockquote> | ||
* tuples are dynamically sized | |||
* tuples can store mixed types | |||
* tuples can contain other tuples | |||
<syntaxhighlight lang="rust"> | |||
var = (1, "two", 3.14) | |||
var.0 // item at index 1 | |||
</syntaxhighlight> | |||
</blockquote><!-- tuples --> | </blockquote><!-- tuples --> | ||
Revision as of 02:34, 1 September 2021
Literals
'a' // char "abc" // string 1234 // i32 3.14 // f32 true/false // bool1_000 // == 1000 1.000_000 // == 1.000000
Primitives
Text
string
"abcd" // stringchar
char 'a' // character (single)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
f32 f64Boolean
true false
Collections
tuples
- tuples are dynamically sized
- tuples can store mixed types
- tuples can contain other tuples
var = (1, "two", 3.14) var.0 // item at index 1arrays