84 lines
1.6 KiB
Plaintext
84 lines
1.6 KiB
Plaintext
const is a thing
|
||
const convention is all upper with _
|
||
const evaluation info: https://doc.rust-lang.org/reference/const_eval.html
|
||
|
||
you can add arbitray scopes to modify local variables or for other purposes!
|
||
{
|
||
some random shit;
|
||
}
|
||
|
||
https://doc.rust-lang.org/book/ch03-02-data-types.html
|
||
|
||
scalars:
|
||
ints
|
||
floats
|
||
bools
|
||
chars
|
||
integer types:
|
||
8-bit i8 u8
|
||
16-bit i16 u16
|
||
32-bit i32 u32
|
||
64-bit i64 u64
|
||
128-bit i128 u128
|
||
arch isize usize
|
||
|
||
number literals
|
||
decimal 1_024
|
||
hex 0xff
|
||
oct 0o77
|
||
binary 0b1100_1011_0100_0001
|
||
byte b'E'
|
||
|
||
release builds have no overflow wrap checking
|
||
don't rely on this behavior
|
||
|
||
explicitly use
|
||
`wrapping_*` methods to do this
|
||
such as wrapping_add
|
||
Return the None value if there is overflow with the checked_* methods
|
||
Return the value and a boolean indicating whether there was overflow with the overflowing_* methods
|
||
|
||
wtf is this:
|
||
Saturate at the value’s minimum or maximum values with saturating_* methods
|
||
|
||
there are f32 and f64 floats. f64 is default cause they are about the same speed
|
||
|
||
normal math operators
|
||
int division is floor
|
||
remainder % exists
|
||
|
||
all operators:
|
||
https://doc.rust-lang.org/book/appendix-02-operators.html
|
||
|
||
|
||
type annotation:
|
||
|
||
let var: type = val;
|
||
|
||
Rust’s char type is four bytes in size and represents a Unicode Scalar Value
|
||
|
||
Compound types
|
||
|
||
primitive compound types:
|
||
tuples
|
||
arrays
|
||
|
||
Tuples:
|
||
fixed length combo of types
|
||
type is ()
|
||
|
||
pulling out the elements of a tuple into individual variables is called destructuring
|
||
|
||
Arrays:
|
||
fixed type fixed length
|
||
[]
|
||
|
||
init:
|
||
let a: [1, 2, 3];
|
||
let a: [3, 0]; // set every element to same value
|
||
reference:
|
||
let first = a[0];
|
||
they are allocated on stack
|
||
|
||
|