Join Abhiram Ravikumar for an in-depth discussion in this video Ownership rules, part of First Look: Rust.
- [Instructor] Let's create a new project called ownership…and here, we'll see the three rules…of ownership that Rust has.…Let's cd into the project and we're all set.…The first rule is that each variable in Rust has a value…and a variable itself is called its owner.…So here, let's declare a variable x and assign it to one.…
Let's open up our project…and let's declare a variable x here.…Now, the scope of the variable here…is through the main function.…Now, if in case I have another scope…inside the main function with an opening curly braces…and the closing curly braces and I have my x here,…this will be inaccessible in the main function.…
As we can see, the scope in Rust starts from a curly braces…and ends when the curly braces ends.…So now, what we can do is…we can have an if condition…and I'll remove the scoping variable here…so that we have only the x.…If x equal equal to one, then let's enter this call loop…and let me declare a variable here.…
Then if I want to access the value of A here…that is totally possible.…
- Installing Rust
- Data types
- Adjusting memory allocation
- Setting up race conditions
- Working with functions
- Exploring references and borrowing
- Using structs
- Method syntax
- Demonstrating recoverable errors with Result
- Working with enums
- Getting user input
Skill Level Beginner
1. Hello, Rust!
2. Basic Programming Concepts
3. Ownership in Rust
4. Data Handling and Pattern Matching in Rust
5. Error Handling
6. Sample Rust Project: The Guessing Game
Next steps1m 14s
- Mark as unwatched
- Mark all as unwatched
Are you sure you want to mark all the videos in this course as unwatched?
This will not affect your course history, your reports, or your certificates of completion for this course.Cancel
Take notes with your new membership!
Type in the entry box, then click Enter to save your note.
1:30Press on any video thumbnail to jump immediately to the timecode shown.
Notes are saved with you account but can also be exported as plain text, MS Word, PDF, Google Doc, or Evernote.