I watched some videos today and here are some notes I took:
- A function not ending in a semicolon being a expression versus a statement is odd.
- A function having a return statement can end in semicolon and be an expression.
- Stack is LIFO. Stack can only hold data of a fixed size. A double quoted string is fixed length. A String::from is dynamic length and stored on the Heap.
- When a value is put in the Heap, the Heap is searched for space large enough to hold the element (out of order, versus the Stack always in LIFO order).
- All Heap values have a ‘pointer’ value in the Stack.
- When a variable is passed into a function the function takes ‘ownership’ of the variable. Three ways to ‘fix’ this issue:
- Clone traight, potentially performance impacting.
- Copy traight (which requires Clone traight). Copy is explicit and Clone is implicit (in the way its called .clone() versus not).
- Use a READ_ONLY_REFERENCE of a variable using the “&” on the parameter name.
- With variables to functions, the MUTABLE_REFERENCE can only be applied once, versus the READ_ONLY_REFERENCE which can have many.
- Lifetimes
- Begin with a single quote.
- Are only relevant for references.
- They dont change the lifetimes of the parameters.
- They can be inferred
I found these videos interesting: