1 00:00:06,630 --> 00:00:07,800 - Okay, so here we are. 2 00:00:07,800 --> 00:00:10,260 We're about to dive into the wonderful world of Rust. 3 00:00:10,260 --> 00:00:12,150 First of all, let's say a few words 4 00:00:12,150 --> 00:00:13,920 about what Rust actually is 5 00:00:13,920 --> 00:00:17,340 as a programming language and how to install the compiler. 6 00:00:17,340 --> 00:00:19,020 So it's a flexible language, 7 00:00:19,020 --> 00:00:21,453 it has low level access and fast. 8 00:00:22,350 --> 00:00:24,750 It gives you the power and the speed 9 00:00:24,750 --> 00:00:26,670 and rigor and safety that you'd need 10 00:00:26,670 --> 00:00:29,070 to write applications of all type. 11 00:00:29,070 --> 00:00:33,720 Quite similar in essence to C++ in terms of its remit, 12 00:00:33,720 --> 00:00:37,080 but in terms of the actual language itself, quite different. 13 00:00:37,080 --> 00:00:40,620 So I programmed in C++ for 20, 30 years. 14 00:00:40,620 --> 00:00:42,360 When I learned Rust, I was quite surprised, 15 00:00:42,360 --> 00:00:45,060 genuinely surprised about how some things work. 16 00:00:45,060 --> 00:00:46,620 Pleasantly surprised as well. 17 00:00:46,620 --> 00:00:49,410 Also a little bit worried about the C++ code 18 00:00:49,410 --> 00:00:51,210 I've been writing for the last 30 years. 19 00:00:51,210 --> 00:00:53,430 How was that actually working in practice? 20 00:00:53,430 --> 00:00:57,360 So what do people use Rust for? 21 00:00:57,360 --> 00:00:59,610 Pretty much any kind of application, actually. 22 00:00:59,610 --> 00:01:02,490 You can use Rust to create low-level applications, 23 00:01:02,490 --> 00:01:03,570 the kind of things that you might 24 00:01:03,570 --> 00:01:05,910 traditionally use C++ to do. 25 00:01:05,910 --> 00:01:08,880 You can happily do that in Rust very easily. 26 00:01:08,880 --> 00:01:10,950 But you can also use Rust to create 27 00:01:10,950 --> 00:01:13,080 high-level business applications as well. 28 00:01:13,080 --> 00:01:17,640 So for example, applications that talk to a database, 29 00:01:17,640 --> 00:01:19,890 that have a REST API. 30 00:01:19,890 --> 00:01:21,720 These aren't the main use cases of Rust, 31 00:01:21,720 --> 00:01:23,640 but it's certainly possible to use Rust 32 00:01:23,640 --> 00:01:26,430 in these kind of scenarios as well. 33 00:01:26,430 --> 00:01:28,020 You can write tool sets. 34 00:01:28,020 --> 00:01:30,480 For example, much of Windows these days 35 00:01:30,480 --> 00:01:32,340 is actually written in Rust. 36 00:01:32,340 --> 00:01:35,010 It was originally written in C and C++. 37 00:01:35,010 --> 00:01:37,680 And Microsoft have rewritten large chunks in Rust 38 00:01:37,680 --> 00:01:39,213 because it's kind of safer, 39 00:01:40,520 --> 00:01:43,860 more safety checks built into the language in Rust. 40 00:01:43,860 --> 00:01:47,310 And in a similar kind of vein, you can write products. 41 00:01:47,310 --> 00:01:51,000 So for example, much of the Firefox browser these days 42 00:01:51,000 --> 00:01:53,010 is actually written in Rust as well. 43 00:01:53,010 --> 00:01:57,810 So you can be quite comfortable that Rust is solid 44 00:01:58,710 --> 00:02:03,710 and proven and usable as a language going forward. 45 00:02:04,140 --> 00:02:07,260 So obviously, you're gonna have to have a compiler. 46 00:02:07,260 --> 00:02:08,850 The way you install a compiler, 47 00:02:08,850 --> 00:02:10,290 it depends on whether you are running 48 00:02:10,290 --> 00:02:13,350 on Linux, Mac, or Windows. 49 00:02:13,350 --> 00:02:16,620 So if you're running on a Linux box or a Mac Box, 50 00:02:16,620 --> 00:02:18,960 you can run this curl command here. 51 00:02:18,960 --> 00:02:22,203 And what that does is to install a tool called rustup. 52 00:02:23,250 --> 00:02:25,140 And then once you've got rustup installed, 53 00:02:25,140 --> 00:02:28,380 you can then use that to install the Rust compiler 54 00:02:28,380 --> 00:02:30,030 on your machine. 55 00:02:30,030 --> 00:02:31,710 Quite straightforward. 56 00:02:31,710 --> 00:02:33,510 If you're running on a Windows box, 57 00:02:33,510 --> 00:02:36,300 then you can go to this website instead. 58 00:02:36,300 --> 00:02:39,439 And if you go through the process, 59 00:02:39,439 --> 00:02:41,880 you'll notice that it also asks you to install 60 00:02:41,880 --> 00:02:45,810 the C++ build tools for Visual Studio. 61 00:02:45,810 --> 00:02:47,160 So I'm just gonna go to this website 62 00:02:47,160 --> 00:02:48,603 and show you how that looks. 63 00:02:49,620 --> 00:02:51,060 So here we are. 64 00:02:51,060 --> 00:02:54,960 You can either install the 32 bit version of Rust 65 00:02:54,960 --> 00:02:56,550 or the 64 Bit version 66 00:02:56,550 --> 00:03:00,330 which is probably what most people would go for these days. 67 00:03:00,330 --> 00:03:02,460 You'll also notice that it mentions here 68 00:03:02,460 --> 00:03:07,200 about installing Visual Studio C++ build tools. 69 00:03:07,200 --> 00:03:09,090 So you probably wanna do that first. 70 00:03:09,090 --> 00:03:10,890 I'll just show what that looks like. 71 00:03:11,880 --> 00:03:14,820 Okay, so basically just click this big button here 72 00:03:14,820 --> 00:03:17,070 to install the C++ build tools 73 00:03:17,070 --> 00:03:19,890 upon which the Rust compiler builds. 74 00:03:19,890 --> 00:03:21,870 There's a bit of explanation here 75 00:03:21,870 --> 00:03:24,270 about what the build tools are for, 76 00:03:24,270 --> 00:03:27,690 obviously for writing native C++ applications, 77 00:03:27,690 --> 00:03:30,573 but for various other kinds of scenario as well. 78 00:03:31,530 --> 00:03:33,120 So for example, Rust, 79 00:03:33,120 --> 00:03:37,080 it talks here about why Rust uses the C++ build tools. 80 00:03:37,080 --> 00:03:39,270 Okay, but you don't need to actually read any of that 81 00:03:39,270 --> 00:03:40,860 unless you're particularly interested. 82 00:03:40,860 --> 00:03:43,320 You just need to click this big button here 83 00:03:43,320 --> 00:03:45,180 to install the build tools. 84 00:03:45,180 --> 00:03:49,020 So do that first and that'll take you 5, 10 minutes. 85 00:03:49,020 --> 00:03:51,300 And then if I go back to the first page, 86 00:03:51,300 --> 00:03:54,300 then install the rustup tool 87 00:03:54,300 --> 00:03:56,550 and it'll install a compiler for you. 88 00:03:56,550 --> 00:04:01,550 I'll also mention a bit later on in this lesson 89 00:04:01,560 --> 00:04:03,270 about the Playground. 90 00:04:03,270 --> 00:04:07,410 So the Playground is quite a handy online Rust compiler. 91 00:04:07,410 --> 00:04:09,660 So even if you don't have the Rust compiler 92 00:04:09,660 --> 00:04:11,220 installed on your machine, 93 00:04:11,220 --> 00:04:14,160 you can still start writing Rust code here 94 00:04:14,160 --> 00:04:15,750 and running it locally, 95 00:04:15,750 --> 00:04:17,500 in the internet connection, I mean. 96 00:04:19,350 --> 00:04:22,140 Just to get a first hands-on. 97 00:04:22,140 --> 00:04:23,580 Okay, so we're gonna come back 98 00:04:23,580 --> 00:04:26,490 and look at the syntax for Rust code 99 00:04:26,490 --> 00:04:28,470 and the kind of the rules 100 00:04:28,470 --> 00:04:30,600 and things you can do and things you can't do. 101 00:04:30,600 --> 00:04:32,730 We'll come back and have a look at that later. 102 00:04:32,730 --> 00:04:35,190 But for now, I guess what we'll just do 103 00:04:35,190 --> 00:04:37,570 before we wrap up this first quick section 104 00:04:38,851 --> 00:04:41,970 is to ensure that the Rust compiler has been installed. 105 00:04:41,970 --> 00:04:45,090 The application here in the online Playground 106 00:04:45,090 --> 00:04:46,680 has actually compiled properly 107 00:04:46,680 --> 00:04:49,140 which was quite nice, but let's just check 108 00:04:49,140 --> 00:04:51,810 that the compiler has been installed properly 109 00:04:51,810 --> 00:04:53,670 on our machine. 110 00:04:53,670 --> 00:04:54,960 Okay, so what you should find 111 00:04:54,960 --> 00:04:58,560 is if you open up a terminal window or command window 112 00:04:58,560 --> 00:05:02,580 and run the Rust compiler rustc --version, 113 00:05:02,580 --> 00:05:05,910 just a quick sanity check that it is installed properly. 114 00:05:05,910 --> 00:05:08,940 So here's my command window, running Windows as you can see, 115 00:05:08,940 --> 00:05:13,893 run the Rust compiler and then --version. 116 00:05:14,910 --> 00:05:16,800 And it should tell me the version of Rust 117 00:05:16,800 --> 00:05:18,540 installed on my machine. 118 00:05:18,540 --> 00:05:21,390 It's Rust 1.68.2. 119 00:05:21,390 --> 00:05:23,520 By the time you're watching this video recording, 120 00:05:23,520 --> 00:05:25,230 it's probably gonna be a different number, 121 00:05:25,230 --> 00:05:27,000 but as long as it's installed, 122 00:05:27,000 --> 00:05:28,500 then looks like we're good to go. 123 00:05:28,500 --> 00:05:30,480 So what we're gonna do for the rest of this lesson 124 00:05:30,480 --> 00:05:33,990 is to start looking at the syntax of a Rust application 125 00:05:33,990 --> 00:05:36,060 and actually compile it and run it. 126 00:05:36,060 --> 00:05:39,240 And then I'm gonna introduce you to a tool called Cargo, 127 00:05:39,240 --> 00:05:41,010 which is a kind of one stop shop 128 00:05:41,010 --> 00:05:43,830 for creating an application, building it, 129 00:05:43,830 --> 00:05:45,990 and running it all at once. 130 00:05:45,990 --> 00:05:47,840 Okay, so see you in the next session.