1 00:00:00,650 --> 00:00:05,530 In this lecture, we are going to explore the starter project generated by cargo. 2 00:00:05,840 --> 00:00:07,670 Let's begin with the route files. 3 00:00:07,970 --> 00:00:13,490 The first file is a get ignore file get is a popular tool for managing projects. 4 00:00:13,700 --> 00:00:15,560 You're very likely familiar with it. 5 00:00:15,860 --> 00:00:18,080 It's a standard tool among developers. 6 00:00:18,380 --> 00:00:21,660 You can write a list of files to prevent them from being committed. 7 00:00:22,340 --> 00:00:26,810 Mighty Falls Cargo recommends not committing a directory called targets. 8 00:00:27,260 --> 00:00:31,130 Our project doesn't have this directory, but it will in the future. 9 00:00:31,430 --> 00:00:35,630 The target directory contains the executable generated by rust. 10 00:00:35,900 --> 00:00:38,570 In a moment, we will look at building the project. 11 00:00:39,050 --> 00:00:39,830 Moving on. 12 00:00:39,860 --> 00:00:43,220 The next file is called Cargo Talkto EML. 13 00:00:43,550 --> 00:00:45,920 It's a configuration file for cargo. 14 00:00:46,220 --> 00:00:50,840 We can compare it to the package JSON file for Node.js projects. 15 00:00:51,200 --> 00:00:56,420 It's possible you may not have syntax highlighting for this type of file out of the box. 16 00:00:56,660 --> 00:01:00,140 Visual Studio Code does not support HTML files. 17 00:01:00,410 --> 00:01:06,710 We can install an extension to enable syntax highlighting switch over to the Extensions tab. 18 00:01:06,980 --> 00:01:11,060 We're going to search for an extension called even better Comal. 19 00:01:13,810 --> 00:01:16,180 Install this extension for VSC. 20 00:01:16,480 --> 00:01:19,660 It's going to provide support for TOEFL files. 21 00:01:19,960 --> 00:01:23,770 In addition, this extension can validate and format our code. 22 00:01:24,160 --> 00:01:28,870 After installing this extension, let's switch back to our configuration file. 23 00:01:29,170 --> 00:01:31,510 The code should be highlighted in your editor. 24 00:01:31,750 --> 00:01:32,350 Perfect. 25 00:01:32,830 --> 00:01:34,570 Let's review the file together. 26 00:01:34,820 --> 00:01:38,770 TOEFL files are very simple at the top of the file. 27 00:01:38,800 --> 00:01:40,690 We have something called a table. 28 00:01:41,470 --> 00:01:46,450 A table is a fancy word for describing different sections of the tile iiml file. 29 00:01:46,780 --> 00:01:49,960 It keeps our configuration organized into groups. 30 00:01:50,350 --> 00:01:54,400 Tables are written with square brackets surrounding the name of the table. 31 00:01:54,910 --> 00:01:59,200 Cargo will define two tables called package and dependencies. 32 00:01:59,590 --> 00:02:03,190 The package table contains settings for describing the project. 33 00:02:03,460 --> 00:02:11,110 Settings are written as key value pairs, so for example, we have the name and version of our project. 34 00:02:11,620 --> 00:02:14,200 You're more than free to modify these values. 35 00:02:14,380 --> 00:02:18,760 However, there are rules you should be aware of when changing these values. 36 00:02:18,940 --> 00:02:24,130 Keep in mind, they'll be read by cargo when its managing or compiling your project. 37 00:02:24,430 --> 00:02:27,310 Luckily, there are descriptions for these settings. 38 00:02:27,550 --> 00:02:33,940 If you hover your mouse over the name key, a description will appear with detailed information, according 39 00:02:33,940 --> 00:02:34,930 to the description. 40 00:02:35,110 --> 00:02:38,860 The name key may only contain alphanumeric characters. 41 00:02:39,400 --> 00:02:43,990 You should always consult with the documentation before modifying these values. 42 00:02:44,230 --> 00:02:50,170 Speaking of documentation, I provide a link to the official documentation page for this file. 43 00:02:51,390 --> 00:02:54,810 This page goes into detail on every setting available. 44 00:02:55,140 --> 00:02:58,230 Feel free to check it out after you finish this course. 45 00:02:58,530 --> 00:03:01,590 First, let's go back to the configuration file. 46 00:03:04,280 --> 00:03:11,690 Out of these settings, the most critical setting is the addition rust is continuously evolving as changes 47 00:03:11,690 --> 00:03:12,980 are made to the language. 48 00:03:13,190 --> 00:03:18,050 There are possible breaking changes for the best backward compatibility. 49 00:03:18,200 --> 00:03:21,860 Rust is broken into additions as of this course. 50 00:03:21,980 --> 00:03:24,260 The latest addition is 2018. 51 00:03:24,530 --> 00:03:30,380 However, its 2021 rust is due for a new addition within the next two months. 52 00:03:31,010 --> 00:03:35,640 If your project contains the 2021 edition, that's perfectly fine. 53 00:03:35,990 --> 00:03:42,410 Our code will be compatible with future editions, so you don't have to revert this option to 2018. 54 00:03:43,100 --> 00:03:45,830 There's another table called Dependencies. 55 00:03:46,160 --> 00:03:51,080 If you would like to install a community package you can list under this table. 56 00:03:51,470 --> 00:03:54,050 By default, this table will be empty. 57 00:03:54,440 --> 00:04:01,820 Dependencies are a topic we will explore in a future lecture that wraps up the cargo akio EML file. 58 00:04:02,450 --> 00:04:07,130 The last thing generated for our project is a directory called Source. 59 00:04:07,550 --> 00:04:10,790 We can write our project code inside this folder. 60 00:04:11,210 --> 00:04:14,600 Cargo creates a file called Main Port R-S. 61 00:04:14,900 --> 00:04:17,540 It's the main entry point of our project. 62 00:04:17,899 --> 00:04:22,610 If we open this file, we'll be given a basic example of a rust file. 63 00:04:22,970 --> 00:04:27,590 Rust files are identified by their extensions, which is R-S. 64 00:04:28,190 --> 00:04:32,510 It's possible you may not have syntax highlighting for rust files. 65 00:04:32,900 --> 00:04:35,750 There's a community extension for rust files. 66 00:04:35,930 --> 00:04:38,600 The name of this extension is called Rust. 67 00:04:38,870 --> 00:04:40,700 Install it for VSC. 68 00:04:43,420 --> 00:04:46,570 After installing it, we can switch back to our file. 69 00:04:46,870 --> 00:04:51,370 The code generated by cargo will output a Hello World message. 70 00:04:51,640 --> 00:04:54,460 We'll talk about the details in a future lecture. 71 00:04:54,730 --> 00:04:58,780 For now, let's try testing the compiler in the terminal. 72 00:04:58,840 --> 00:05:02,380 We can compile rust by running B cargo run command. 73 00:05:05,000 --> 00:05:10,250 Behind the scenes, cargo will use the Rust See tool to compile projects. 74 00:05:10,580 --> 00:05:14,240 Most developers prefer to compile rust through cargo. 75 00:05:14,570 --> 00:05:18,590 The compiler will tell us how long our project took to compile. 76 00:05:18,920 --> 00:05:25,430 It will even run the project after compilation projects will not run unless our program is error free. 77 00:05:26,000 --> 00:05:30,650 If we had an error, the console would output information related to the error. 78 00:05:31,010 --> 00:05:35,210 This default behavior allows us to catch errors before production. 79 00:05:35,840 --> 00:05:39,560 In some cases, you may not care about the status of the builds. 80 00:05:39,860 --> 00:05:45,830 You can ignore these statuses by adding the minus queue option to the cargo run command. 81 00:05:48,410 --> 00:05:52,440 By adding this option, these statuses are ignored from the output. 82 00:05:52,790 --> 00:05:56,540 We only get the output from our program moving along. 83 00:05:56,600 --> 00:06:00,470 You can find the build of your project in a folder called targets. 84 00:06:00,770 --> 00:06:05,030 If this folder doesn't exist, cargo will create it beforehand. 85 00:06:05,390 --> 00:06:08,420 The files in this folder can be deployed to production. 86 00:06:09,080 --> 00:06:14,270 In addition to the target folder, a file called cargo lock is created. 87 00:06:14,600 --> 00:06:18,050 If we open this file, a comment will be written at the top. 88 00:06:18,380 --> 00:06:23,240 It says the following this file is automatically generated by cargo. 89 00:06:23,480 --> 00:06:25,880 It is not intended for manual editing. 90 00:06:26,540 --> 00:06:32,030 As the comment says, We can safely ignore this file cargo completely manages it. 91 00:06:32,300 --> 00:06:33,020 Congrats. 92 00:06:33,170 --> 00:06:39,080 We've successfully created and built our first robust project in the next couple of lectures. 93 00:06:39,200 --> 00:06:42,170 We're going to begin learning the fundamentals of rust. 94 00:06:42,440 --> 00:06:45,080 We'll continue working on our new project.