1 00:00:05,940 --> 00:00:09,900 And this lecture we're going to start talking about utility traits. 2 00:00:09,900 --> 00:00:16,740 And utility traits are a grab bag of various traits from the standard library that have enough of an 3 00:00:16,740 --> 00:00:21,570 impact on the way rest is written, that it's important for us to be familiar with them. 4 00:00:21,570 --> 00:00:25,740 So the first one that we're going to look at is the drop tray. 5 00:00:26,550 --> 00:00:31,590 And we've heard the word drop being used kind of throughout this course. 6 00:00:31,590 --> 00:00:37,380 And when we talk about dropping and rust, we are referring to the freeing of the resources the value 7 00:00:37,380 --> 00:00:38,070 is using. 8 00:00:38,340 --> 00:00:44,850 Drops occur in a number of situations, such as when a variable goes out of scope at the end of an expression, 9 00:00:44,850 --> 00:00:48,240 removing elements from a vector and the list goes on and on. 10 00:00:49,510 --> 00:00:54,240 Luckily Rust almost always will handle this for us, but it is an important trait to know. 11 00:00:54,250 --> 00:00:56,680 So let's look at how we can use it. 12 00:00:56,740 --> 00:01:06,430 So we'll piggyback off of our struct course and what we'll do is we'll implement drop for course. 13 00:01:08,370 --> 00:01:14,010 And then we're going to have the drop function, which is going to contain a mutable reference to the 14 00:01:14,010 --> 00:01:15,180 self. 15 00:01:15,450 --> 00:01:21,450 And then in here, just to demonstrate how it works, we'll say we're dropping. 16 00:01:23,070 --> 00:01:26,490 And then we'll just say self dot art author. 17 00:01:28,570 --> 00:01:36,880 So now when we come down here, we can manually call this ourselves and we can say drop course one because 18 00:01:36,880 --> 00:01:39,010 that is what used our course. 19 00:01:39,840 --> 00:01:44,580 Struct and now if we run it, we'll see that it says dropping Tyler. 20 00:01:44,640 --> 00:01:55,080 So we manually call this drop trait and we manually freed up our resources, but we could delete this 21 00:01:55,080 --> 00:01:55,620 line. 22 00:01:57,210 --> 00:02:01,050 And rerun this and see that it still calls dropping. 23 00:02:01,080 --> 00:02:11,040 Tyler because here is where course one went out of scope and so it called our implementation of drop 24 00:02:11,310 --> 00:02:11,970 which. 25 00:02:13,140 --> 00:02:20,070 We told to hey print out dropping Tyler and then free up the resources so. 26 00:02:20,790 --> 00:02:22,320 That is what the drop trait is. 27 00:02:22,320 --> 00:02:24,750 And now let's go look at a couple more. 28 00:02:24,900 --> 00:02:27,960 Starting off with what the clone trade is.