Char
chars are single unicode scalars that are denoted by single quotes.
they are not interchangeable like in other non-typed languages
chars are not a single byte but 4 bytes in Rust.
Arrays
A fixed-size list of elements of the same type
by default are immutable but you can still use mut
shorthand for initializing an array filled with zeros.
get length; println!("list length: {}", list.len());
slices
are portions of data structures, and are a safe way to reference certain parts of data.
slices can be immutable or mutable
very similar to a reference.
Str
is the primitive string type for Rust but it’s an unsized type but is useful once you use it as a reference; &str
.
Tuples
Ordered list of fixed size
you can access values of a tuple through deconstruction;
IF statements
something cool you can do with Rust is this
other than that Rust uses “else if” like everybody else.
loops
- loop
- while
- for
the loop
keyword is the simplest loop in Rust and is an infinite loop.
while
loop works the same way as most other languages.
For loop
for loop does not have a “c-style” for loop, best thing we have is something like this:
you can also use break
to stop iteration early
you can also label loops: