Rust datatypes: Difference between revisions
From wikinotes
(→char) |
(→Text) |
||
Line 4: | Line 4: | ||
== Text == | == Text == | ||
<blockquote> | <blockquote> | ||
=== string === | |||
<blockquote> | |||
<syntaxhighlight lang="rust"> | |||
"abcd" // string | |||
</syntaxhighlight> | |||
</blockquote><!-- string --> | |||
=== char === | === char === | ||
<blockquote> | <blockquote> | ||
<syntaxhighlight lang="rust"> | <syntaxhighlight lang="rust"> | ||
char | char | ||
'a' | 'a' // character (single) | ||
</syntaxhighlight> | </syntaxhighlight> | ||
</blockquote><!-- char --> | </blockquote><!-- char --> |
Revision as of 02:18, 1 September 2021
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
arrays