1 00:00:06,702 --> 00:00:08,280 - In a typical Rust program, 2 00:00:08,280 --> 00:00:10,620 you're gonna have a lot of structure types. 3 00:00:10,620 --> 00:00:13,290 For example, in our simple demo project, 4 00:00:13,290 --> 00:00:17,310 we've got a structure called Point, Point3D, 5 00:00:17,310 --> 00:00:19,950 three-dimensional point, and Employee, 6 00:00:19,950 --> 00:00:22,110 and we could have hundreds of others. 7 00:00:22,110 --> 00:00:25,050 So it's common to define each structure 8 00:00:25,050 --> 00:00:27,570 in a separate module, in a separate file. 9 00:00:27,570 --> 00:00:30,663 Basically, that gives you readability and maintainability. 10 00:00:30,663 --> 00:00:32,610 Each file is quite small 11 00:00:32,610 --> 00:00:34,710 because it justifies one structure type. 12 00:00:34,710 --> 00:00:37,061 It's easier to read, easier to maintain. 13 00:00:37,061 --> 00:00:40,050 Also, it works easier if you've got a group of developers. 14 00:00:40,050 --> 00:00:42,630 Each developer can be working on a different file 15 00:00:42,630 --> 00:00:43,770 at the same time. 16 00:00:43,770 --> 00:00:45,870 So, generally, a good idea. 17 00:00:45,870 --> 00:00:47,280 You don't have to do it this way. 18 00:00:47,280 --> 00:00:49,560 It would be allowable to put all your structures 19 00:00:49,560 --> 00:00:52,620 into a single file, but then, it'll start to get massive. 20 00:00:52,620 --> 00:00:54,750 You're gonna have potentially hundreds of structures 21 00:00:54,750 --> 00:00:55,583 all in a single file. 22 00:00:55,583 --> 00:00:57,603 It's gonna get difficult to deal with. 23 00:00:58,680 --> 00:01:00,930 Okay, so this is the approach we're gonna take. 24 00:01:00,930 --> 00:01:03,120 We're gonna put each of these structure types 25 00:01:03,120 --> 00:01:05,580 into a separate file or separate module 26 00:01:05,580 --> 00:01:07,320 and we're gonna discuss how that actually works 27 00:01:07,320 --> 00:01:08,523 in a Rust application. 28 00:01:09,420 --> 00:01:11,760 We'll have a file called point.rs, 29 00:01:11,760 --> 00:01:13,680 which defines a Point structure, 30 00:01:13,680 --> 00:01:17,880 and point3d.rs, which defines our Point3D structure, 31 00:01:17,880 --> 00:01:21,360 and an Employee structure defined an employee.rs. 32 00:01:21,360 --> 00:01:23,160 So this is entirely optional. 33 00:01:23,160 --> 00:01:27,060 It's up to you how you organize your structures into files. 34 00:01:27,060 --> 00:01:28,470 It's not like Java 35 00:01:28,470 --> 00:01:31,140 where you have to have one public class per file. 36 00:01:31,140 --> 00:01:34,260 Rust lets you organize it as you like. 37 00:01:34,260 --> 00:01:35,490 So that's what we're going to do anyway. 38 00:01:35,490 --> 00:01:38,880 We're gonna have a separate structure per file, 39 00:01:38,880 --> 00:01:41,640 and we need to see how that works in Rust. 40 00:01:41,640 --> 00:01:44,880 The way Rust works with multi file projects 41 00:01:44,880 --> 00:01:47,910 is not entirely intuitive. 42 00:01:47,910 --> 00:01:49,387 It's something that most Rust developers 43 00:01:49,387 --> 00:01:52,530 scratch their heads over initially trying to understand it. 44 00:01:52,530 --> 00:01:54,090 So I'm gonna explain how this actually works. 45 00:01:54,090 --> 00:01:57,660 How does it work if you want to have lots and lots of files 46 00:01:57,660 --> 00:01:58,803 in an application? 47 00:01:59,730 --> 00:02:01,200 Right, so what we've done 48 00:02:01,200 --> 00:02:04,350 is we've organized our project into modules. 49 00:02:04,350 --> 00:02:06,990 From the top, at the top of our project, 50 00:02:06,990 --> 00:02:10,800 at the top of our crate, our crate root directory, 51 00:02:10,800 --> 00:02:15,270 in main.rs, I've declared a module called mytypes, okay? 52 00:02:15,270 --> 00:02:19,440 So as we know, when we declared a module called mytypes, 53 00:02:19,440 --> 00:02:21,030 what the compiler then looks for 54 00:02:21,030 --> 00:02:24,660 is a file called mytypes.rs. 55 00:02:24,660 --> 00:02:26,340 And up until now, 56 00:02:26,340 --> 00:02:28,860 what we've been seeing is inside that file, 57 00:02:28,860 --> 00:02:33,090 we can define our structures in here, like that. 58 00:02:33,090 --> 00:02:37,110 So we can define our Point structure, our Point3D structure, 59 00:02:37,110 --> 00:02:40,920 and the Employee structure all in mytypes.rs. 60 00:02:40,920 --> 00:02:42,390 But like I was saying, 61 00:02:42,390 --> 00:02:45,390 that's gonna start to get quite unwieldy. 62 00:02:45,390 --> 00:02:48,960 If you are gonna put all your structures into a single file 63 00:02:48,960 --> 00:02:50,940 and you've got like a hundred structures, 64 00:02:50,940 --> 00:02:53,250 that's never gonna scale up. 65 00:02:53,250 --> 00:02:54,810 So there's a different technique. 66 00:02:54,810 --> 00:02:56,730 When you input the module 67 00:02:56,730 --> 00:02:59,490 and you have a file called mytypes.rs, 68 00:02:59,490 --> 00:03:02,760 rather than defining all the structures in here, 69 00:03:02,760 --> 00:03:04,380 what you can do is you can push 'em down 70 00:03:04,380 --> 00:03:05,640 into another submodule. 71 00:03:05,640 --> 00:03:07,650 So you have two levels of module. 72 00:03:07,650 --> 00:03:10,200 From the crate, from the top of the crate, 73 00:03:10,200 --> 00:03:12,540 you have a module called mytypes 74 00:03:12,540 --> 00:03:15,361 which looks for a file called mytypes.rs. 75 00:03:15,361 --> 00:03:17,910 But then it pushes those structure definitions down 76 00:03:17,910 --> 00:03:20,700 into second division modules, if you like. 77 00:03:20,700 --> 00:03:23,400 I've got a second-level module which are made public, 78 00:03:23,400 --> 00:03:25,950 so I can access elsewhere in the application, 79 00:03:25,950 --> 00:03:29,460 called point, point3d, and employee. 80 00:03:29,460 --> 00:03:31,410 So where do these files live? 81 00:03:31,410 --> 00:03:34,200 Point, point3d, and employee. 82 00:03:34,200 --> 00:03:35,970 And this is how it works. 83 00:03:35,970 --> 00:03:38,580 If you have a module called mytypes, 84 00:03:38,580 --> 00:03:41,790 the compiler will look for mytypes.rs. 85 00:03:41,790 --> 00:03:44,040 And if you declare submodules in there, 86 00:03:44,040 --> 00:03:45,690 it'll look for a folder, 87 00:03:45,690 --> 00:03:49,740 the same name as your model name, like that, okay? 88 00:03:49,740 --> 00:03:53,040 So you have a a file called mytypes.rs 89 00:03:53,040 --> 00:03:55,680 which introduces submodules, 90 00:03:55,680 --> 00:03:57,450 and those submodules are in a directory 91 00:03:57,450 --> 00:03:59,220 also called mytypes. 92 00:03:59,220 --> 00:04:02,760 And in here, I define my point, my point3d, 93 00:04:02,760 --> 00:04:04,650 and my employee structure. 94 00:04:04,650 --> 00:04:07,497 So this is a namespace hierarchy as well. 95 00:04:07,497 --> 00:04:09,810 These structures, if you wanted to access them 96 00:04:09,810 --> 00:04:13,740 in your application as we go to do shortly, you'd specify, 97 00:04:13,740 --> 00:04:15,483 you'd use the crate keyword, 98 00:04:16,440 --> 00:04:20,354 which basically takes you to the root namespace. 99 00:04:20,354 --> 00:04:24,810 There's a hierarchy of modules or namespaces in Rust, 100 00:04:24,810 --> 00:04:27,780 and the crate keyword takes you to the root level 101 00:04:27,780 --> 00:04:28,800 in your hierarchy. 102 00:04:28,800 --> 00:04:30,360 So it takes you to the crate. 103 00:04:30,360 --> 00:04:32,873 And then you'd say ::mytypes, okay? 104 00:04:37,530 --> 00:04:39,377 And that kind of takes you to here 105 00:04:40,529 --> 00:04:45,529 and to here as well, mytypes.rs and the mytypes folder. 106 00:04:45,600 --> 00:04:50,497 And then you'd say ::point, for example, 107 00:04:52,260 --> 00:04:55,524 because that's the name of a submodule. 108 00:04:55,524 --> 00:04:57,960 Mytypes is one module 109 00:04:57,960 --> 00:05:01,170 and it has a submodule called point, okay? 110 00:05:01,170 --> 00:05:05,160 So that effectively takes you down to that file. 111 00:05:05,160 --> 00:05:07,860 And then in there, we've got a structure 112 00:05:07,860 --> 00:05:09,810 called Point with a capital P. 113 00:05:09,810 --> 00:05:12,063 So you'd say ::Point. 114 00:05:14,370 --> 00:05:16,410 All right, so that's how it works. 115 00:05:16,410 --> 00:05:20,463 You have a top-level module if you like, called mytypes, 116 00:05:21,690 --> 00:05:24,243 which introduces a sub-level module called point. 117 00:05:25,170 --> 00:05:27,663 And in there, you define the Point structure. 118 00:05:28,530 --> 00:05:30,930 So from the top of the crate, you go to mytypes, 119 00:05:32,820 --> 00:05:36,090 and then you go to point, and in point, 120 00:05:36,090 --> 00:05:40,050 you'll find the Point structure defined like so. 121 00:05:40,050 --> 00:05:43,260 So this isn't probably what you expected, 122 00:05:43,260 --> 00:05:44,880 but it is the way to do it. 123 00:05:44,880 --> 00:05:47,010 Define a module at the top. 124 00:05:47,010 --> 00:05:49,143 In that module file, declare submodules. 125 00:05:50,010 --> 00:05:52,920 And those submodules are basically files 126 00:05:52,920 --> 00:05:54,480 in the mytypes directory. 127 00:05:54,480 --> 00:05:56,430 So you have a mytypes file, 128 00:05:56,430 --> 00:05:59,610 and each submodules are defined in a mytypes folder. 129 00:05:59,610 --> 00:06:01,893 So it's a nesting arrangement like so. 130 00:06:03,146 --> 00:06:05,310 So that's what we've done in the project. 131 00:06:05,310 --> 00:06:07,260 So let's take a closer look at these structures, 132 00:06:07,260 --> 00:06:10,080 Point, Point3D, and Employee. 133 00:06:10,080 --> 00:06:12,360 Here is my Point structure, 134 00:06:12,360 --> 00:06:16,140 and it's defined in the mytypes folder 135 00:06:16,140 --> 00:06:19,440 in a file called point.rs, as just discussed. 136 00:06:19,440 --> 00:06:23,580 And as you notice, I've defined the structure as public, 137 00:06:23,580 --> 00:06:25,830 so it's visible in other modules. 138 00:06:25,830 --> 00:06:28,380 And I've defined the fields as public as well, 139 00:06:28,380 --> 00:06:31,890 so they're also visible in other modules, okay? 140 00:06:31,890 --> 00:06:34,050 So everything's visible. 141 00:06:34,050 --> 00:06:36,030 We'll improve on this later on. 142 00:06:36,030 --> 00:06:39,130 Having public data in the structure 143 00:06:40,020 --> 00:06:43,260 isn't necessarily particularly object oriented. 144 00:06:43,260 --> 00:06:45,540 So what we'll do later on is we'll revert 145 00:06:45,540 --> 00:06:47,490 to making that data private 146 00:06:47,490 --> 00:06:49,800 and then we'll kind of define getters and setters, 147 00:06:49,800 --> 00:06:50,970 like you might do in other languages. 148 00:06:50,970 --> 00:06:51,900 But for now, 149 00:06:51,900 --> 00:06:54,350 we'll just make everything public for simplicity. 150 00:06:55,530 --> 00:06:58,440 Right, so as well as having data in a structure, 151 00:06:58,440 --> 00:07:00,630 we also have functionality. 152 00:07:00,630 --> 00:07:05,610 So here is my structure data definition as we just saw. 153 00:07:05,610 --> 00:07:09,030 And here is the implementation of functionality 154 00:07:09,030 --> 00:07:10,650 for that structure. 155 00:07:10,650 --> 00:07:12,750 Now, a couple of things to notice here. 156 00:07:12,750 --> 00:07:15,420 The implementation block itself isn't public. 157 00:07:15,420 --> 00:07:18,570 You don't declare the implementation block as public. 158 00:07:18,570 --> 00:07:21,810 Rather, what you do is you declare individual methods 159 00:07:21,810 --> 00:07:25,080 as being public on an as needed basis. 160 00:07:25,080 --> 00:07:30,080 So I've decided to make my print method public 161 00:07:30,240 --> 00:07:33,270 and the move_by method public, 162 00:07:33,270 --> 00:07:36,480 but I've chosen to keep the log method private, okay? 163 00:07:36,480 --> 00:07:41,250 Private means it's only visible inside this file, okay? 164 00:07:41,250 --> 00:07:43,920 So it's kind of like a private method in a class 165 00:07:43,920 --> 00:07:45,150 in other languages. 166 00:07:45,150 --> 00:07:48,720 So in my main code, when I create a Point object, 167 00:07:48,720 --> 00:07:51,090 I'll be able to invoke the print and the move_by 168 00:07:51,090 --> 00:07:54,000 in my client code, but I won't be able to invoke log 169 00:07:54,000 --> 00:07:56,330 because it's not public, okay? 170 00:07:56,330 --> 00:07:58,410 So the structure itself is public, 171 00:07:58,410 --> 00:07:59,850 the fields can be public, 172 00:07:59,850 --> 00:08:02,430 and then the individual methods can be public or not, 173 00:08:02,430 --> 00:08:04,080 depending on what you need to do. 174 00:08:05,430 --> 00:08:09,930 Right, so here is my usage of the Point structure. 175 00:08:09,930 --> 00:08:12,930 So to simplify syntax, 176 00:08:12,930 --> 00:08:17,370 I'm going to introduce or import the Point structure 177 00:08:17,370 --> 00:08:20,130 into scope with a use statement. 178 00:08:20,130 --> 00:08:22,563 So from the top level of my crate, 179 00:08:23,460 --> 00:08:25,650 go into the mytypes module, 180 00:08:25,650 --> 00:08:28,320 which define a submodule called point, 181 00:08:28,320 --> 00:08:32,760 which contained a Point class or Point structure. 182 00:08:32,760 --> 00:08:34,770 Once I've done that, I can then use Point here 183 00:08:34,770 --> 00:08:39,180 to create a Point object to invoke its public move_by method 184 00:08:39,180 --> 00:08:41,583 and to invoke its public to_string method. 185 00:08:42,720 --> 00:08:45,330 Right, so we can access the point type here 186 00:08:45,330 --> 00:08:47,430 because we defined it as public, 187 00:08:47,430 --> 00:08:50,910 we can access the public members in the Point structure, 188 00:08:50,910 --> 00:08:53,583 the data potentially and the methods. 189 00:08:54,420 --> 00:08:58,110 Right, so time to show all this in the actual demo project. 190 00:08:58,110 --> 00:09:00,503 So we'll go back and do lesson_11_structs_functionality. 191 00:09:01,890 --> 00:09:03,990 The files we're going to look at, we'll go, 192 00:09:03,990 --> 00:09:05,010 we look at the top level, 193 00:09:05,010 --> 00:09:07,470 everything really begins at main.rs. 194 00:09:07,470 --> 00:09:10,983 So that'll introduce our submodule called mytypes. 195 00:09:12,240 --> 00:09:14,580 And when we look in mytypes.rs. 196 00:09:14,580 --> 00:09:18,570 It introduces three sub-submodules, 197 00:09:18,570 --> 00:09:21,390 point, point3, and employee. 198 00:09:21,390 --> 00:09:25,020 In particular, we're going to look at the mytypes/point.rs, 199 00:09:25,020 --> 00:09:26,760 which defines the Point structure, 200 00:09:26,760 --> 00:09:28,260 and then we're going to use it 201 00:09:28,260 --> 00:09:32,553 in our code demo_modular_code.rs, and then we run it. 202 00:09:33,510 --> 00:09:34,743 So let's take a look. 203 00:09:36,060 --> 00:09:38,854 So from the top, main.rs, 204 00:09:38,854 --> 00:09:41,340 it defines a module called mytypes. 205 00:09:41,340 --> 00:09:43,740 So immediately, but while I'm at it, 206 00:09:43,740 --> 00:09:45,150 lemme just uncomment the code 207 00:09:45,150 --> 00:09:48,780 that's actually going to be running here while I'm here. 208 00:09:48,780 --> 00:09:52,473 Right, so when you define the module, 209 00:09:53,400 --> 00:09:55,980 when you define the mytypes module, 210 00:09:55,980 --> 00:09:58,950 the compiler will look for a file called mytypes, 211 00:09:58,950 --> 00:09:59,783 and here it is. 212 00:09:59,783 --> 00:10:03,090 And in there, we could have defined the structures there, 213 00:10:03,090 --> 00:10:05,700 all of them, but then it would've been massive. 214 00:10:05,700 --> 00:10:10,700 So instead, I've defined three second division modules, 215 00:10:10,707 --> 00:10:13,560 employee, point, and point3d. 216 00:10:13,560 --> 00:10:15,960 And because I'm in a file called mytypes, 217 00:10:15,960 --> 00:10:19,140 it will look for a folder also called mytypes. 218 00:10:19,140 --> 00:10:19,980 And in there, 219 00:10:19,980 --> 00:10:24,570 it'll expect to find employee, point, and point3d. 220 00:10:24,570 --> 00:10:26,370 And it does, okay? 221 00:10:26,370 --> 00:10:28,890 So in particular, it's the point structure we're looking at. 222 00:10:28,890 --> 00:10:31,650 So let's look at the point module. 223 00:10:31,650 --> 00:10:35,172 And in here, I've defined a Point structure, 224 00:10:35,172 --> 00:10:38,430 which is public and public fields as well. 225 00:10:38,430 --> 00:10:41,280 And then we have the implementation of a Point. 226 00:10:41,280 --> 00:10:42,840 I don't think really there's much here 227 00:10:42,840 --> 00:10:43,980 that we haven't already seen. 228 00:10:43,980 --> 00:10:45,720 So let's just make sure. 229 00:10:45,720 --> 00:10:47,280 Oh, there is one thing actually. 230 00:10:47,280 --> 00:10:50,070 The fact that some of the methods are public, 231 00:10:50,070 --> 00:10:53,640 the print method is public, the to_string is public, 232 00:10:53,640 --> 00:10:56,700 meaning we can access it in a separate file. 233 00:10:56,700 --> 00:10:57,870 The reset function is public. 234 00:10:57,870 --> 00:11:00,810 Oh, and the reset function calls log. 235 00:11:00,810 --> 00:11:02,460 Log, what I've done, 236 00:11:02,460 --> 00:11:05,010 basically, every time I change the value of a point, 237 00:11:05,010 --> 00:11:07,680 I log that change to the console. 238 00:11:07,680 --> 00:11:09,360 So I've got a private log method. 239 00:11:09,360 --> 00:11:13,230 It's private by default, not public, in other words. 240 00:11:13,230 --> 00:11:17,160 And it gets the current time in UTC, 241 00:11:17,160 --> 00:11:20,520 Universal Coordinated Time, and that's an object, 242 00:11:20,520 --> 00:11:23,490 formats it as a string containing just the time. 243 00:11:23,490 --> 00:11:25,713 So that's the timestamp as a string. 244 00:11:26,610 --> 00:11:29,190 And what this log method does 245 00:11:29,190 --> 00:11:34,190 is it outputs a message at a given timestamp. 246 00:11:35,100 --> 00:11:38,013 So the message gets displayed here, 247 00:11:40,530 --> 00:11:43,620 and then it calls self.to_string. 248 00:11:43,620 --> 00:11:46,830 So you are allowed to invoke methods on the same object. 249 00:11:46,830 --> 00:11:49,590 But whenever you access something on your current object, 250 00:11:49,590 --> 00:11:51,570 you've got to say self. 251 00:11:51,570 --> 00:11:55,230 So a Java developer might say this, 252 00:11:55,230 --> 00:11:58,530 a C++ developer might say that, 253 00:11:58,530 --> 00:12:01,230 in those languages you could just say to_string, 254 00:12:01,230 --> 00:12:02,970 and they would implicitly think you were calling 255 00:12:02,970 --> 00:12:04,720 the to_string function on yourself. 256 00:12:05,730 --> 00:12:07,530 But in Rust you have to, 257 00:12:07,530 --> 00:12:10,380 when you are accessing one of your own fields or members, 258 00:12:10,380 --> 00:12:13,560 you have to say self, okay? 259 00:12:13,560 --> 00:12:17,640 So this message, this print string will output a message 260 00:12:17,640 --> 00:12:19,530 passed as a parameter. 261 00:12:19,530 --> 00:12:21,480 The second parameter or the second output 262 00:12:21,480 --> 00:12:25,980 would be the current state of the Point object. 263 00:12:25,980 --> 00:12:30,600 And then it'll also output the timestamp like so, okay? 264 00:12:30,600 --> 00:12:32,940 So it's like a quite a handy log method. 265 00:12:32,940 --> 00:12:37,263 So my reset function, it calls self.log, 266 00:12:38,100 --> 00:12:39,660 and then it resets the point. 267 00:12:39,660 --> 00:12:41,730 And remember, again, when we call self.log, 268 00:12:41,730 --> 00:12:43,620 we can't just say log. 269 00:12:43,620 --> 00:12:47,610 We have to say on the current object, invoke the log method. 270 00:12:47,610 --> 00:12:50,130 And also when you move the point, 271 00:12:50,130 --> 00:12:53,580 it also writes a log message to the console, 272 00:12:53,580 --> 00:12:56,640 and then it moves the point by the delta x and delta y. 273 00:12:56,640 --> 00:13:01,640 So my print, the to_string, the reset, 274 00:13:01,860 --> 00:13:04,017 and the move_by functions are public 275 00:13:04,017 --> 00:13:06,900 and the log method is private. 276 00:13:06,900 --> 00:13:11,900 And my user code here, this is quite straightforward, 277 00:13:12,780 --> 00:13:16,840 I bring the Point structure into scope 278 00:13:17,760 --> 00:13:19,440 so I can use that name directly. 279 00:13:19,440 --> 00:13:24,330 I create a mutable Point, I move it and print it, 280 00:13:24,330 --> 00:13:26,013 I reset it and print it. 281 00:13:26,880 --> 00:13:30,720 If I wanted to, instead of having a use statement here, 282 00:13:30,720 --> 00:13:33,723 I could have used that full syntax here. 283 00:13:34,740 --> 00:13:37,080 And then I wouldn't read the use statement, okay? 284 00:13:37,080 --> 00:13:38,820 And that would actually be fine. 285 00:13:38,820 --> 00:13:43,080 Go to the root level namespace in my application, 286 00:13:43,080 --> 00:13:45,090 go to the mytypes module, 287 00:13:45,090 --> 00:13:47,790 go to the mytypes point submodule. 288 00:13:47,790 --> 00:13:49,830 So it's kind of looking here now. 289 00:13:49,830 --> 00:13:52,440 And in there you, it'll find the Point structure. 290 00:13:52,440 --> 00:13:54,450 Okay, so that would also work, 291 00:13:54,450 --> 00:13:56,820 but getting quite difficult to write, doesn't it? 292 00:13:56,820 --> 00:13:59,370 So let's just revert back to as it was. 293 00:13:59,370 --> 00:14:01,260 Let's have an import statement, 294 00:14:01,260 --> 00:14:04,950 makes our code a lot more short and snappy, 295 00:14:04,950 --> 00:14:07,050 like a baby crocodile. 296 00:14:07,050 --> 00:14:09,810 So I think we're ready to run the application. 297 00:14:09,810 --> 00:14:10,953 Let's run it and see. 298 00:14:12,210 --> 00:14:14,553 After all this, I really hope it works. 299 00:14:17,070 --> 00:14:18,780 Cargo run. 300 00:14:18,780 --> 00:14:20,130 The output that we see. 301 00:14:20,130 --> 00:14:21,430 It's interesting actually. 302 00:14:22,317 --> 00:14:23,150 When you run an application, 303 00:14:23,150 --> 00:14:25,050 the amount of effort we've put in under the covers, 304 00:14:25,050 --> 00:14:25,883 behind the scenes, 305 00:14:25,883 --> 00:14:27,420 there's actually quite a lot. 306 00:14:27,420 --> 00:14:30,840 Having a submodule and then having a a directory, 307 00:14:30,840 --> 00:14:33,060 which implements that submodule 308 00:14:33,060 --> 00:14:34,740 with the classes or the structures. 309 00:14:34,740 --> 00:14:35,850 We've put a lot of effort 310 00:14:35,850 --> 00:14:38,160 into the modularization of our code. 311 00:14:38,160 --> 00:14:40,010 But in terms of what we actually see, 312 00:14:40,980 --> 00:14:42,420 you don't really see the benefit of it yet. 313 00:14:42,420 --> 00:14:44,460 But obviously, as the application grows in size, 314 00:14:44,460 --> 00:14:47,070 that kind of structure is gonna be beneficial. 315 00:14:47,070 --> 00:14:51,120 So there's the log method, About to move the point. 316 00:14:51,120 --> 00:14:54,900 It was currently 10, 20, nearly 2:00 PM here 317 00:14:54,900 --> 00:14:58,200 on a lovely sunny Saturday afternoon here in Swansea. 318 00:14:58,200 --> 00:14:59,460 And then it moved it. 319 00:14:59,460 --> 00:15:01,410 About to reset the point. 320 00:15:01,410 --> 00:15:04,200 That's the current value at that timestamp, 321 00:15:04,200 --> 00:15:07,500 and there's the value of the point afterwards. 322 00:15:07,500 --> 00:15:10,800 Okay, so covered quite a lot of ground in this section. 323 00:15:10,800 --> 00:15:13,410 We talked about how in your main code, 324 00:15:13,410 --> 00:15:15,333 you can define a top level module. 325 00:15:16,320 --> 00:15:18,330 And then in that top level module, 326 00:15:18,330 --> 00:15:20,940 you can define second-level modules. 327 00:15:20,940 --> 00:15:22,230 Those implemented. 328 00:15:22,230 --> 00:15:24,720 If you have a module called mytypes, 329 00:15:24,720 --> 00:15:26,310 the submodules would be in the directory 330 00:15:26,310 --> 00:15:28,043 called mytypes, okay? 331 00:15:28,043 --> 00:15:30,900 And the file names will be the same as the module names. 332 00:15:30,900 --> 00:15:33,000 When it says pub mod employee, 333 00:15:33,000 --> 00:15:36,930 it'll import that code in employee.rs, 334 00:15:36,930 --> 00:15:40,950 and in point.rs, and in point3.rs. 335 00:15:40,950 --> 00:15:43,803 Okay, so now we've set up a good structure going forward.