Rust - The Programing Language

A brief breakdown of Rust features.

Comienza Ya. Es Gratis
ó regístrate con tu dirección de correo electrónico
Rust - The Programing Language por Mind Map: Rust - The Programing Language

1. basic data types

1.1. scalar

1.1.1. integer

1.1.1.1. i8

1.1.1.2. u8

1.1.1.3. i16

1.1.1.4. u16

1.1.1.5. i32

1.1.1.6. u32

1.1.1.7. i64

1.1.1.8. u64

1.1.1.8.1. 1_000_000 = 1000000

1.1.1.9. i128

1.1.1.10. u128

1.1.1.11. architecture specific

1.1.1.11.1. isize

1.1.1.11.2. usize

1.1.2. floating point

1.1.2.1. f32

1.1.2.2. f64

1.1.2.2.1. this is the default

1.1.3. boolean

1.1.3.1. true

1.1.3.2. false

1.1.4. character

1.1.4.1. char

1.1.4.1.1. single char

1.1.4.1.2. unicode

1.2. compound

2. variables

2.1. mutable

2.1.1. it's value is allowed to be changed

2.1.2. `let mut <variable_name>:<Optional Data Type>`

2.2. imutable

2.2.1. cannot be changed once it's set

2.2.2. `let my_variable = "what"`

2.3. assignment

2.3.1. `my_var = my_value`

3. constants

3.1. value cannot be changed

3.2. they are a **compile-time** representation

3.3. it's substituted by its value at compile-time

3.4. usually are ALL_CAPS

3.5. it's **mandatory** to specify a **data type** of constants

4. operators

4.1. arithmetic operators

4.1.1. +

4.1.2. -

4.1.3. *

4.1.4. /

4.1.5. %

4.1.5.1. mod

4.2. comparison operators

4.2.1. ==

4.2.2. !=

4.2.3. <

4.2.4. >

4.2.5. <=

4.2.6. >=

4.3. logical operators

4.3.1. &&

4.3.2. ||

4.3.3. !

4.4. bitwise operators

4.4.1. &

4.4.2. |

4.4.3. ^

4.4.3.1. logical XOR

4.4.4. <<

4.4.5. >>

4.5. compound assignment operators

4.5.1. +=

4.5.2. -=

4.5.3. *=

4.5.4. /=

4.5.5. %=

4.5.6. &=

4.5.7. |=

4.5.8. ^=

4.5.9. <<=

4.5.10. >>=

5. type casting

5.1. as

6. descision making

6.1. if-else

6.1.1. parenthesis are optional

6.2. match

6.2.1. allows you to use an expression which can evaluate to anything, not just true or false

6.2.2. similar to the switch-case

6.2.3. can be used to assign a value

6.2.4. use `|` to match more than one expression

6.2.5. match arms can have ranges

6.2.6. the first arm to match is always selected

7. **functions**

7.1. definition

7.1.1. fn my_function() {}

7.1.2. arguments

7.1.2.1. fn my_function(arg1: DataType, arg2: DataType) {}

7.1.3. return value

7.1.3.1. fn my_function(arg1: DataType) -> ReturnType {}

7.1.4. arrays and vectors as **arguments**

7.1.4.1. fn my_function(cities: &Vec<String>) {}

7.1.5. returning a vector from a function

7.1.5.1. return type: Vec<Type>

7.2. call

7.2.1. my_function();

8. **structures**

8.1. instantiation

9. **command line arguments**

10. cargo

10.1. new project

10.1.1. `cargo new my_project`

10.2. Cargo.toml

10.2.1. it's like a manifest file

10.2.2. carries metadata about the project

10.3. building

10.3.1. `cargo build`

10.4. running

10.4.1. `cargo run`

11. syntax

11.1. statements

11.1.1. end with `;`

11.2. comments

11.2.1. // single line

11.2.2. /* multi line */

11.3. blocks

11.3.1. are enclosed within `{ }`

11.4. identifiers

11.4.1. has to start with

11.4.1.1. an alphabet letter

11.4.1.2. or an underscore `_`

11.5. keywords

11.5.1. currently in use

11.5.1.1. as

11.5.1.2. async

11.5.1.3. await

11.5.1.4. break

11.5.1.5. const

11.5.1.6. continue

11.5.1.7. crate

11.5.1.8. dyn

11.5.1.9. else

11.5.1.10. enum

11.5.1.11. extern

11.5.1.12. flase

11.5.1.13. fn

11.5.1.14. for

11.5.1.15. if

11.5.1.16. impl

11.5.1.17. in

11.5.1.18. let

11.5.1.19. loop

11.5.1.20. match

11.5.1.21. mod

11.5.1.22. move

11.5.1.23. mut

11.5.1.24. pub

11.5.1.25. ref

11.5.1.26. return

11.5.1.27. self

11.5.1.28. Self

11.5.1.29. static

11.5.1.30. struct

11.5.1.31. super

11.5.1.32. trait

11.5.1.33. true

11.5.1.34. type

11.5.1.35. union

11.5.1.36. unsafe

11.5.1.37. use

11.5.1.38. where

11.5.1.39. while

11.5.2. reserved for future use

11.5.2.1. abstract

11.5.2.2. become

11.5.2.3. box

11.5.2.4. final

11.5.2.5. macro

11.5.2.6. override

11.5.2.7. try

11.5.2.8. typeof

11.5.2.9. unsize

11.5.2.10. do

11.5.2.11. priv

11.5.2.12. virtual

11.5.2.13. yield

12. basic program structure

12.1. console apps

12.1.1. mandatory `main` function

12.1.1.1. the program's entry point

13. create

13.1. it'slike a library

13.2. can contain several modules

13.3. module

13.3.1. is a collection of several items

13.3.1.1. functions

13.3.1.2. types

13.4. path separator (::)

13.4.1. is used to pin point an item or module

14. print

14.1. `print!("text")`

14.2. `println!("text to print on a new line")`

14.3. they are macros

14.4. printing variables

14.4.1. use the `{ }` substitution token

15. user input

15.1. stdin

15.1.1. reading text

15.1.2. reading numbers

16. loops

16.1. keywords

16.1.1. for

16.1.1.1. only works on **Iterators**

16.1.1.2. ranges

16.1.2. loop

16.1.2.1. infinite loop

16.1.2.2. only way to get out of it is using **break**

16.1.3. while

16.1.3.1. parenthesis are optional

16.2. control statements

16.2.1. continue

16.2.2. break

17. **collections**

17.1. **arrays**

17.1.1. let num_array: [i32; 3] = [80, 90, 100];

17.1.2. data type can be optional as long as the items are of the same type

17.1.3. length

17.1.3.1. array.len()

17.1.4. turn into **Iterator**

17.1.4.1. array.iter()

17.1.5. **fixed length**

17.2. **array slices**

17.2.1. a **reference** to a **part** of the array

17.2.2. **cannot** exist on its own

17.2.3. doesn't have memory regions assined for it

17.2.4. can also be considered as a **view** into the array

17.2.5. syntax

17.2.5.1. &array_variable[1..2]

17.3. **vectors**

17.3.1. its size can **increase**

17.3.2. growable arrays

17.3.3. **std::Vec** module

17.3.4. variable creation

17.3.4.1. use the **vec!** macro

17.3.4.1.1. let cities = vec!["Canoas", "Palhoca", "POA"];

17.3.4.2. using the **new()** method

17.3.4.2.1. let mut cities = Vec<String> = Vec::new();

17.3.5. are iterators by default

17.3.6. adding elements

17.3.6.1. vec.push()

17.3.6.2. the variable must be declared as **mut**

18. **strings**

18.1. string literals

18.1.1. type

18.1.1.1. `&str`

18.1.2. `let name:&str = "Adriano";`

18.1.3. `let name = "Adriano";`

18.1.4. `let name: &str;` `name = "Adriano";`

18.2. **std::String**

18.2.1. dynamic heap type string

18.2.2. creating

18.2.2.1. `let mut name = String::new();`

18.2.2.2. let city = String::from("Canoas");

18.2.3. pushing strings and chars to a string variable

18.2.3.1. the variable must be declared as **mut**

18.2.3.2. my_string.push_str("Another string");

18.2.3.3. my_string.push('c');

18.3. string formatting

18.3.1. array

18.3.1.1. println!("numbers: {:?}", number_array);

18.4. concatenation

18.4.1. let str5 = str1 + &str2 + " " + &str3;

18.5. replace

18.5.1. sentence.replace("old", "new");

18.6. tokenization

18.6.1. sentence.split_whitespace();

18.6.2. sentense.split(",");