1 00:00:05,900 --> 00:00:12,740 To start off our program, we are going to create a new library project using cargo new, and then I'm 2 00:00:12,740 --> 00:00:21,770 going to call my program chat and then we will use the lib parameter and now we can change into that 3 00:00:21,770 --> 00:00:22,670 directory. 4 00:00:22,670 --> 00:00:28,790 And I want to just go ahead and clear out some of this filler code. 5 00:00:30,680 --> 00:00:35,690 Some of the first things that I want to do is add a couple of dependencies that we are going to need 6 00:00:35,690 --> 00:00:37,190 throughout this project. 7 00:00:37,640 --> 00:00:40,460 The first one is async standard. 8 00:00:41,420 --> 00:00:46,880 Latest version one, I would like to use Tokyo. 9 00:00:47,300 --> 00:00:51,170 We're going to use the latest version one. 10 00:00:51,200 --> 00:00:57,950 And then we can also specify the features that we want. 11 00:00:57,950 --> 00:01:00,380 And in this case, we want sync. 12 00:01:02,890 --> 00:01:05,650 I also want Saturday 13 00:01:08,200 --> 00:01:11,710 version latest of one. 14 00:01:13,860 --> 00:01:25,110 And features equal drive and are see. 15 00:01:28,110 --> 00:01:29,160 Features. 16 00:01:30,840 --> 00:01:32,310 And then the last one. 17 00:01:32,340 --> 00:01:34,410 Saturday, Jason. 18 00:01:34,770 --> 00:01:36,690 The latest version of one. 19 00:01:38,370 --> 00:01:43,470 So async standard we are familiar with since we've already used it. 20 00:01:43,470 --> 00:01:51,030 And Tokyo is another collection of asynchronous primitives, which is kind of like async standard. 21 00:01:51,450 --> 00:01:57,020 It is a well known and very widely used crate and it's a pretty large crate. 22 00:01:57,030 --> 00:02:03,300 So since we only need one component from it, we can specify features, which is what we did. 23 00:02:03,300 --> 00:02:06,140 And then we said, Hey, we want sync. 24 00:02:06,150 --> 00:02:12,690 So what that's what cargo's going to do is it's only going to provide us sync from the Tokyo crate. 25 00:02:12,690 --> 00:02:17,940 That way we don't absorb in everything else that comes with Tokyo. 26 00:02:17,970 --> 00:02:19,800 We only get what we need. 27 00:02:20,100 --> 00:02:25,920 And then we have Saturday and Saturday JSON and these are crates that give us easy and efficient tools 28 00:02:25,920 --> 00:02:32,820 for generating and parsing JSON, which is what our chat is going to use to represent data going over 29 00:02:32,820 --> 00:02:33,570 the network. 30 00:02:34,800 --> 00:02:44,280 So now we can create a few additional files and directories to kind of finish setting up our project. 31 00:02:44,280 --> 00:02:49,380 So inside source, we're going to want a new file and we're going to call it Utils. 32 00:02:50,840 --> 00:02:56,240 And then we also want a new directory called Bin for binary. 33 00:02:56,690 --> 00:03:01,190 And then inside of this folder, we want our client. 34 00:03:03,410 --> 00:03:09,410 And then we want another folder called Server, which is where all of our server logic is going to be. 35 00:03:09,590 --> 00:03:15,710 And in this case, we have a couple of files we'll need we'll need a main. 36 00:03:18,090 --> 00:03:20,640 We'll need a connection. 37 00:03:23,480 --> 00:03:25,370 We'll need chats. 38 00:03:27,630 --> 00:03:31,080 And we'll call this one chat map. 39 00:03:33,640 --> 00:03:38,710 So client is a single executable file. 40 00:03:39,040 --> 00:03:43,120 Let me clean up all of these really quickly. 41 00:03:44,220 --> 00:03:44,790 All right. 42 00:03:44,790 --> 00:03:52,830 So our client is a single file executable for the chat and our server is the executable for our server, 43 00:03:52,830 --> 00:03:57,000 which will be spread into those four different files we created. 44 00:03:57,360 --> 00:04:01,050 So now let's take a look at our utils file. 45 00:04:04,360 --> 00:04:09,790 And we can start defining some types that we will use throughout the application. 46 00:04:10,300 --> 00:04:17,920 So Utils is going to contain our utilities that we will use throughout our application. 47 00:04:18,280 --> 00:04:22,240 So the first thing we want is we want our standard air. 48 00:04:24,200 --> 00:04:26,660 And now we're going to create a couple of types. 49 00:04:26,660 --> 00:04:38,240 So our first type is going to be our chat air, which is going to be a smart pointer of a box using 50 00:04:38,240 --> 00:04:48,320 an air, and it's going to have a send sync and a static lifetime. 51 00:04:49,970 --> 00:05:02,420 And then we're also going to create a chat result type over a generic T, which is going to give us 52 00:05:02,420 --> 00:05:06,770 a result or a chat air. 53 00:05:09,110 --> 00:05:13,220 So as we use our own air types, we will see that the question mark. 54 00:05:13,550 --> 00:05:15,800 OPERATOR So the question mark. 55 00:05:15,830 --> 00:05:16,640 Operator. 56 00:05:17,990 --> 00:05:25,100 Well automatically be able to convert different air types into a chat air by using the standard libraries 57 00:05:25,100 --> 00:05:30,650 from trait to the type we implemented right here. 58 00:05:32,040 --> 00:05:34,170 So we will use, send and seek. 59 00:05:34,740 --> 00:05:35,280 Excuse me. 60 00:05:35,280 --> 00:05:45,210 We use send and sync bounds to ensure that if a task that is spawned on another thread fails, it will 61 00:05:45,210 --> 00:05:48,900 be able to safely report the failure up to Main. 62 00:05:49,590 --> 00:05:51,060 So hopefully that makes sense. 63 00:05:51,060 --> 00:05:56,280 And if it doesn't, you'll be able to see it a little bit more as we continue our program. 64 00:05:57,280 --> 00:06:04,240 But now that we have something set up in the next lecture, we will begin working on our chats protocol.