1 00:00:05,570 --> 00:00:06,500 Struck. 2 00:00:07,270 --> 00:00:14,230 Which are short for structures, let you name and package together related values into a single value 3 00:00:14,230 --> 00:00:16,780 so that you can deal with them as a single unit. 4 00:00:17,320 --> 00:00:23,200 Rust has three types of structs a named field tuple like and a unit like. 5 00:00:24,310 --> 00:00:27,250 Named Field Drug gives a name to each component. 6 00:00:27,460 --> 00:00:34,210 A tuple like struc identifies them by the order in which they appear, and a unit like struc actually 7 00:00:34,210 --> 00:00:40,180 has no components at all, which might sound trivial, but we'll be able to make sense of that a little 8 00:00:40,180 --> 00:00:40,960 bit later on. 9 00:00:42,190 --> 00:00:45,910 But for now, let's start and look at a named field. 10 00:00:46,450 --> 00:00:54,580 So we create a struct by using the struct keyword and then the name that we want our drug to be. 11 00:00:54,760 --> 00:00:58,050 So notice that it is capitalized at the first character. 12 00:00:58,060 --> 00:01:01,150 This is known as Camel Case or Pasqual case. 13 00:01:02,160 --> 00:01:06,510 And as the desired format that Rust calls for in this situation. 14 00:01:06,510 --> 00:01:10,800 So we're creating a struct called user and now we're going to give it some. 15 00:01:11,620 --> 00:01:16,990 Attributes and notice how these are key pair values when we do this. 16 00:01:16,990 --> 00:01:21,010 So we're going to have active and it's going to be a boolean. 17 00:01:21,370 --> 00:01:29,680 We're going to have username as a string and then we're going to say the sign and count and it'll be 18 00:01:29,680 --> 00:01:31,990 an unsigned 32 integer. 19 00:01:33,170 --> 00:01:42,290 So to create it user, let's say let user one is equal to user and this is where that key pair value 20 00:01:42,320 --> 00:01:43,340 comes into play. 21 00:01:43,340 --> 00:01:45,800 So we're going to say active. 22 00:01:46,370 --> 00:01:47,000 True. 23 00:01:47,000 --> 00:01:51,680 So our key is active and our value is true. 24 00:01:52,160 --> 00:01:59,780 User name and we're going to do string from Tyler. 25 00:02:04,590 --> 00:02:09,090 And then for our last one, we're going to say our sign and count, which is our. 26 00:02:11,070 --> 00:02:14,370 T and then our value of zero. 27 00:02:15,060 --> 00:02:18,960 So how can we access any of this information? 28 00:02:19,050 --> 00:02:19,800 Well. 29 00:02:20,590 --> 00:02:24,550 We have what's known as the dot notation. 30 00:02:24,700 --> 00:02:28,240 So let's print out my username. 31 00:02:28,240 --> 00:02:31,810 So we're going to say user one and then dot. 32 00:02:32,620 --> 00:02:36,640 And then now you can see that these attributes appear. 33 00:02:36,640 --> 00:02:38,980 So again, I wanted to print out my username. 34 00:02:40,080 --> 00:02:48,120 And this dot notation is how we can access the attributes inside of our. 35 00:02:49,450 --> 00:02:54,310 So now if we run it, I expect it to say Tyler, which is exactly what happened. 36 00:02:54,400 --> 00:02:54,820 All right. 37 00:02:54,820 --> 00:02:55,560 So good. 38 00:02:55,570 --> 00:03:00,580 So something else that we can do is we can create. 39 00:03:01,860 --> 00:03:06,230 A function that's going to build our user for us. 40 00:03:06,240 --> 00:03:17,460 So in here we just want to pass in my username and we want it to be a string and then we want a user 41 00:03:18,690 --> 00:03:19,860 to be returned. 42 00:03:20,970 --> 00:03:26,910 So in here we're going to return a user and we're going to just leave username. 43 00:03:27,700 --> 00:03:32,650 And then we're going to have active as true. 44 00:03:34,200 --> 00:03:38,910 And then we're going to auto assign our sign and count to one. 45 00:03:39,390 --> 00:03:41,170 So what's happening here? 46 00:03:41,190 --> 00:03:43,890 So how come we don't have to assign anything to username? 47 00:03:43,920 --> 00:03:50,520 Well, it's smart enough to realize, hey, we have a username parameter and a username attribute. 48 00:03:51,450 --> 00:03:54,000 So it's automatically going to map those two together. 49 00:03:54,000 --> 00:04:00,900 So we don't have to have any logic down here to basically say, hey, username is user name because 50 00:04:00,900 --> 00:04:02,100 that's the same thing it's doing. 51 00:04:02,100 --> 00:04:06,840 But Russ is smart enough to do that and make that correlation for us, and then we're just going to 52 00:04:06,840 --> 00:04:12,090 go ahead and preset in these values for every user that we do this way. 53 00:04:12,480 --> 00:04:14,550 So let's go ahead and build a user. 54 00:04:14,550 --> 00:04:18,690 So we're going to say let user two is equal to build user. 55 00:04:18,690 --> 00:04:26,250 And then in here we're going to say we want the name to be string from 56 00:04:28,740 --> 00:04:31,680 and we'll do Tyler two. 57 00:04:34,350 --> 00:04:40,200 And then let's just go ahead and print out our username again to make sure that that that worked the 58 00:04:40,200 --> 00:04:41,580 way that we were intending. 59 00:04:44,920 --> 00:04:45,990 And that's exactly what we got. 60 00:04:46,000 --> 00:04:47,350 So we got Tyler, too. 61 00:04:48,310 --> 00:04:49,060 So. 62 00:04:49,930 --> 00:04:54,580 Now what are the tuple like structs that we talked about? 63 00:04:55,760 --> 00:05:03,150 So remember to pull structs, identify the values by the order in which they appear. 64 00:05:03,170 --> 00:05:09,290 So if we come up here and we go struct and capital coordinates. 65 00:05:10,640 --> 00:05:16,310 Then we can do I 32, high 32 and then I 32. 66 00:05:18,190 --> 00:05:21,430 So now we can come down here. 67 00:05:24,500 --> 00:05:25,580 And say. 68 00:05:35,090 --> 00:05:36,030 Get rid of that. 69 00:05:36,050 --> 00:05:36,680 There we go. 70 00:05:37,640 --> 00:05:38,150 All right. 71 00:05:39,350 --> 00:05:46,820 So now we can say let Cordes equal coordinates 1 to 3. 72 00:05:47,270 --> 00:05:48,380 So it was able. 73 00:05:49,090 --> 00:05:56,560 To say, okay, we have an I 30 to another I 32 and another I 32 and that's all there is to it for the 74 00:05:56,560 --> 00:05:57,400 tuple structs. 75 00:05:57,400 --> 00:06:04,000 So remember tuple like structs identify the values by the order in which they appear. 76 00:06:04,750 --> 00:06:08,710 But now what about a unit like stroke? 77 00:06:09,160 --> 00:06:14,530 So a unit like stroke can be done like this. 78 00:06:15,550 --> 00:06:18,520 So now we have a unit like struck. 79 00:06:18,520 --> 00:06:20,350 What's the use of this? 80 00:06:21,410 --> 00:06:29,240 Well, we've actually already have used a unit struck prior in this course when we did the one. 81 00:06:30,270 --> 00:06:31,380 To five. 82 00:06:32,280 --> 00:06:42,000 Collect method when we were for like a range when we were populating a vector, the dot dot is shorthand 83 00:06:42,000 --> 00:06:44,520 for the struct value range. 84 00:06:44,730 --> 00:06:55,680 So it's range and it is set up from like start one and then end five. 85 00:06:56,070 --> 00:07:03,690 So we will be able to see how these unit like structures are a little bit more useful when we start 86 00:07:03,690 --> 00:07:07,830 to talk about traits a little later on in this course. 87 00:07:07,830 --> 00:07:14,310 But for now, the main structure we're going to be using are the named field ones. 88 00:07:15,290 --> 00:07:24,200 So what we need to do now is start looking at how we can implement methods on these structs.