Fireship · @fireship

Rust in 100 Seconds

Uploaded October 12, 2021 · Length 2:29

Rust in 100 Seconds

Summary

rust programming language basics, memory safety, and performance optimization in 100 seconds

  • rust programming language
  • memory safety
  • performance optimization
  • ownership and borrowing
  • cargo package manager

Transcript preview

The first 2 minutes of the transcript. Select a timestamp to watch that moment on YouTube.

  1. 0:00

    rust a memory safe compiled programming

  2. 0:02

    language that delivers highlevel

  3. 0:04

    Simplicity with low-level performance

  4. 0:06

    it's a popular choice for Building

  5. 0:07

    Systems where performance is absolutely

  6. 0:09

    critical like game engines databases or

  7. 0:12

    operating systems and is an excellent

  8. 0:14

    choice when targeting web assembly it

  9. 0:16

    started as a side project of gr on

  10. 0:18

    in 2007 who named it after the rust

  11. 0:21

    fungus it was sponsored by Mozilla in

  12. 0:23

    2009 and has been ranked the most Lov

  13. 0:25

    programming language every year since

  14. 0:27

    2016 with its fans being known as

  15. 0:29

    restation traditionally highle languages

  16. 0:32

    provide a garbage collector to Nerf your

  17. 0:34

    control over memory management while

  18. 0:36

    lower level languages provide functions

  19. 0:38

    like free and allocate to shoot yourself

  20. 0:40

    in the foot rust takes a different

  21. 0:42

    approach it has no garbage collector but

  22. 0:44

    achieves memory safety with a concept

  23. 0:46

    known as ownership and borrowing by

  24. 0:48

    default every variable in Rust is

  25. 0:50

    immutable this allows values to be used

  26. 0:52

    in the stack memory which has minimal

  27. 0:53

    performance overhead however mutable

  28. 0:55

    values or objects with an unknown size

  29. 0:58

    at compile time are stored in the keep

  30. 1:00

    memory every value in a rust program is

  31. 1:02

    assigned to a single variable known as

  32. 1:04

    its owner when that variable goes out of

  33. 1:06

    scope the memory allocated to it is

  34. 1:08

    dropped automatically in some cases

  35. 1:10

    though you may want to pass a reference

  36. 1:12

    to a different part of the program

  37. 1:13

    borrowing allows you to access a

  38. 1:15

    reference in memory without taking

  39. 1:17

    ownership of it there are a ton of rules

  40. 1:19

    to go along with the system that the r

  41. 1:21

    borrow Checker will validate at compile

  42. 1:23

    time these rules keep your code safe

  43. 1:25

    while providing absolute control over

  44. 1:27

    performance rust also has a package

  45. 1:29

    manager called cargo where each

  46. 1:30

    individual package is a crate to get

  47. 1:33

    started install rest then run cargo new

  48. 1:35

    from the command line in the main. RS

  49. 1:37

    file you'll find a main function which

  50. 1:39

    is where the program will start

  51. 1:41

    executing declare a variable with let

  52. 1:43

    followed by its name and type the value

  53. 1:45

    can't be changed or reassigned by

  54. 1:47

    default so add mut to make it mutable

  55. 1:49

    the name of the variable is the owner a

  56. 1:51

    reference to its location and memory can

  57. 1:53

    be Borrowed by other parts of the

  58. 1:54

    program by prefixing it with an Amper

  59. 1:56

    sand then use a macro like print line to

  60. 1:59

    log the value to the standard output