Join Abhiram Ravikumar for an in-depth discussion in this video Building structs using values, part of First Look: Rust.
[Man] Consider a scenario where you have a username…and an email address…and you'd like to build a struct from those given values.…Rust has a shorthand…for precisely such an operation.…Let's write a new function over here…build user.…So this function take email…as a string input…followed by the username as a string…and then the return type of this function…is a struct…which is the user here…so since you're building the struct here…we start with the name of the struct we want to build…followed be the curly braces…and all the values that go into the struct…we write email here…and then username…since we are passing email and username…from an external function call…we are taking that from the parameters data key…whereas we have two other variables active…that we are setting to true…and the sign in count…which is set to one.…
So we are setting these values explicitly…because we are not passing them in the parameter list…so let me save this.…So this is how you will build a particular struct…using given values.…This function uses the field in it shorthand…
- 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
Programming Foundations: Data Structures (2014)with Simon Allardice2h 29m Intermediate
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.