Skip to content

Instantly share code, notes, and snippets.

@LispyAriaro
Last active October 5, 2017 09:15
Show Gist options
  • Save LispyAriaro/259be85d0cb57c33db94b50773a562ab to your computer and use it in GitHub Desktop.
Save LispyAriaro/259be85d0cb57c33db94b50773a562ab to your computer and use it in GitHub Desktop.
Rustlang quick helpful rules
- There can be only one owner of a value
- Ownership of a value can be given to something else. When this is done through re-assignment, it is called Move semantics.
- However, primitive types like integers that have the Copy trait already implemented for them will be copied when re-assigned.
These are called Copy Types.
- Passing a value directly to a function gives ownership to that function
- Values initialized within a function WILL BE DROPPED AT THE END OF THE FUNCTION except you go out of your way to return it.
- A value can be lent to a something else. This is done by passing a reference to the value with the & symbol
- When calling a function that returns a value, you might get an owned value or a borrowed value.
When you have a borrowed value, it means it is a reference
- Cloning a value is frowned upon
- Return value of a function is the last expression in the function without semicolon. Very important
- println! has to be a macro instead of a function because it has to check its variable number of arguments at compile time
-
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment