1 00:00:06,600 --> 00:00:09,960 - We've already seen how to define static local variables. 2 00:00:09,960 --> 00:00:11,640 As you can see in this example, 3 00:00:11,640 --> 00:00:14,070 I've got a function, and inside the function, 4 00:00:14,070 --> 00:00:16,860 I've declared a static variable called MESSAGE. 5 00:00:16,860 --> 00:00:18,570 It's a string. 6 00:00:18,570 --> 00:00:21,540 Technically speaking, it's a string slice. 7 00:00:21,540 --> 00:00:24,090 We'll need to discuss that syntax later on. 8 00:00:24,090 --> 00:00:26,520 And I've given it a value, in this simple example, 9 00:00:26,520 --> 00:00:30,297 I've given it a hard coded constant string, "Hello." 10 00:00:31,200 --> 00:00:35,700 Right, so when you declare a local static variable, 11 00:00:35,700 --> 00:00:38,670 it's only visible inside that function. 12 00:00:38,670 --> 00:00:41,670 And it retains its values across calls. 13 00:00:41,670 --> 00:00:44,400 So, it's local, and it is statically allocated. 14 00:00:44,400 --> 00:00:46,830 Initialized on first entry, 15 00:00:46,830 --> 00:00:48,810 and it retains its value thereafter. 16 00:00:48,810 --> 00:00:49,860 And of course, like I was saying, 17 00:00:49,860 --> 00:00:51,960 you can declare it as multiple, if you want, 18 00:00:51,960 --> 00:00:53,070 if you need to change it, 19 00:00:53,070 --> 00:00:55,380 you have to be a bit careful about that, with thread safety. 20 00:00:55,380 --> 00:00:56,553 But it is possible. 21 00:00:58,020 --> 00:01:02,010 Right, so that's for local statics. 22 00:01:02,010 --> 00:01:04,650 It's also possible to have statics declared globally. 23 00:01:04,650 --> 00:01:06,540 Global static variables, 24 00:01:06,540 --> 00:01:08,280 which can be accessed by all functions, 25 00:01:08,280 --> 00:01:12,273 potentially in the current file and other files as well. 26 00:01:13,140 --> 00:01:17,010 So, the rules for declaring a static global variable 27 00:01:17,010 --> 00:01:19,170 are the same as for static locals. 28 00:01:19,170 --> 00:01:21,000 You have the static keyword 29 00:01:21,000 --> 00:01:25,500 and you specify the variable name in capital letters. 30 00:01:25,500 --> 00:01:26,910 You specify the data type, 31 00:01:26,910 --> 00:01:28,710 you have to specify the data type, 32 00:01:28,710 --> 00:01:30,870 it doesn't allow type inference. 33 00:01:30,870 --> 00:01:32,970 And you supply a value. 34 00:01:32,970 --> 00:01:36,180 Typically a constant, although possibly a runtime value. 35 00:01:36,180 --> 00:01:38,910 So, there is a, well, there's several differences, 36 00:01:38,910 --> 00:01:40,110 but one key difference 37 00:01:40,110 --> 00:01:44,310 compared to other languages like C++. 38 00:01:44,310 --> 00:01:46,470 When you declare a global in C++, 39 00:01:46,470 --> 00:01:48,870 you just declare it at the top of a file. 40 00:01:48,870 --> 00:01:50,820 But in Rust, I mean, you would declare it 41 00:01:50,820 --> 00:01:54,990 at the top of a file, but you also have to say static, okay? 42 00:01:54,990 --> 00:01:57,090 And you don't have to do that in C++, 43 00:01:57,090 --> 00:01:59,373 but you do have in Rust. 44 00:02:00,390 --> 00:02:01,620 So, here's an example. 45 00:02:01,620 --> 00:02:03,390 I've got a static global variable, 46 00:02:03,390 --> 00:02:06,750 presumably called MESSAGE, it's a string, a string slice. 47 00:02:06,750 --> 00:02:08,910 And I've given it the simple value, "Hello." 48 00:02:08,910 --> 00:02:12,750 And I could then potentially access that message anywhere 49 00:02:12,750 --> 00:02:17,750 in my file, or anywhere in my project if it's public. 50 00:02:17,850 --> 00:02:20,040 So, let's talk about visibility. 51 00:02:20,040 --> 00:02:21,960 If you want to make a global variable visible 52 00:02:21,960 --> 00:02:24,090 to other modules, other files, 53 00:02:24,090 --> 00:02:26,370 then you declare it as public like this. 54 00:02:26,370 --> 00:02:30,690 So if I've got a module called module1.rs, I declared it 55 00:02:30,690 --> 00:02:35,460 as a public static, I can then use it in another module. 56 00:02:35,460 --> 00:02:36,587 Okay? 57 00:02:36,587 --> 00:02:39,060 So, in order to be able to access it in another module, 58 00:02:39,060 --> 00:02:42,360 you'd have to, first of all, in your main code, 59 00:02:42,360 --> 00:02:45,600 you'd have to introduce module1. 60 00:02:45,600 --> 00:02:48,720 And then, you'd potentially import the variable name 61 00:02:48,720 --> 00:02:50,220 into the current scope. 62 00:02:50,220 --> 00:02:51,053 Okay? 63 00:02:51,053 --> 00:02:53,130 So, it could look something like this. 64 00:02:53,130 --> 00:02:54,960 And import 65 00:02:54,960 --> 00:02:56,400 the code. 66 00:02:56,400 --> 00:02:58,533 And basically declare the sub module. 67 00:02:59,520 --> 00:03:03,990 And then, the use statement from the module1, 68 00:03:03,990 --> 00:03:07,983 introduce this symbol into the current scope. 69 00:03:07,983 --> 00:03:08,816 Okay? 70 00:03:08,816 --> 00:03:09,649 So, declare a sub module, 71 00:03:09,649 --> 00:03:13,830 and then make this symbol name directly visible, 72 00:03:13,830 --> 00:03:15,630 so I can then use it here. 73 00:03:15,630 --> 00:03:16,463 MESSAGE. 74 00:03:16,463 --> 00:03:20,523 If I hadn't imported the variable like this, 75 00:03:22,410 --> 00:03:25,050 then here, I'd have had to have prefixed it 76 00:03:25,050 --> 00:03:27,050 with a module name, something like this. 77 00:03:28,680 --> 00:03:33,680 module1:: MESSAGE. 78 00:03:33,810 --> 00:03:36,570 Okay? Which isn't the hardest thing in the world. 79 00:03:36,570 --> 00:03:38,220 But it might get a bit repetitive. 80 00:03:38,220 --> 00:03:41,670 So, often, you just use the use statement 81 00:03:41,670 --> 00:03:44,370 to basically input that name message 82 00:03:44,370 --> 00:03:45,543 into the current scope. 83 00:03:46,980 --> 00:03:47,910 Right! 84 00:03:47,910 --> 00:03:51,960 If you want to initialize a global variable lazily 85 00:03:51,960 --> 00:03:54,570 at runtime, similar to what we looked at 86 00:03:54,570 --> 00:03:58,620 in the previous demo, actually, you use the Lazy wrapper. 87 00:03:58,620 --> 00:04:01,170 So, here, I've got a static, 88 00:04:01,170 --> 00:04:03,000 I've called it GLOBAL_TIMESTAMP. 89 00:04:03,000 --> 00:04:04,800 Whatever name you wanna choose. 90 00:04:04,800 --> 00:04:08,820 And I want to initialize it with a runtime expression. 91 00:04:08,820 --> 00:04:10,620 You can't just initialize it directly 92 00:04:10,620 --> 00:04:12,060 because of thread safety. 93 00:04:12,060 --> 00:04:15,000 You wrap it in a Lazy box. 94 00:04:15,000 --> 00:04:17,880 And the first time you try to use this variable anywhere, 95 00:04:17,880 --> 00:04:20,490 then the code that you supply here 96 00:04:20,490 --> 00:04:23,010 in the new function, this closure, 97 00:04:23,010 --> 00:04:26,610 this green closure, will be executed on first usage. 98 00:04:26,610 --> 00:04:29,550 The value that this closure returns will be the value 99 00:04:29,550 --> 00:04:32,043 that gets placed inside the Lazy wrapper. 100 00:04:32,880 --> 00:04:35,430 So, the Lazy object is a thread-safe wrapper 101 00:04:35,430 --> 00:04:36,660 around the value. 102 00:04:36,660 --> 00:04:40,740 The initialization code in my closure, it runs once 103 00:04:40,740 --> 00:04:43,173 the first time you try to use this variable. 104 00:04:44,040 --> 00:04:45,176 Okay? 105 00:04:45,176 --> 00:04:47,370 So, basically the same as what we had for static locals, 106 00:04:47,370 --> 00:04:49,440 but at a global scope. 107 00:04:49,440 --> 00:04:51,540 So, let's see an example 108 00:04:51,540 --> 00:04:54,840 in the lesson six scope ownership project. 109 00:04:54,840 --> 00:04:58,530 Let's have a look at demo_static_global.rs, 110 00:04:58,530 --> 00:05:00,270 and then we'll run it. 111 00:05:00,270 --> 00:05:02,550 So, here we are in the project. 112 00:05:02,550 --> 00:05:05,037 We're going to look at demo_static_global. 113 00:05:06,960 --> 00:05:09,450 And let me highlight 114 00:05:09,450 --> 00:05:12,003 a few things in here. 115 00:05:13,680 --> 00:05:14,513 Right! 116 00:05:14,513 --> 00:05:15,346 So, 117 00:05:16,470 --> 00:05:19,770 remember, that I've specified once_cell? 118 00:05:19,770 --> 00:05:20,880 That crate? 119 00:05:20,880 --> 00:05:21,960 And chrono? 120 00:05:21,960 --> 00:05:26,163 That crate are both being introduced into my project. 121 00:05:27,150 --> 00:05:31,530 And the once_cell crate defines the Lazy structure, 122 00:05:31,530 --> 00:05:35,160 the wrapper that allows Lazy thread safe initialization, 123 00:05:35,160 --> 00:05:38,970 and the chrono crate defines a couple of date 124 00:05:38,970 --> 00:05:41,160 and time-related structures. 125 00:05:41,160 --> 00:05:42,900 I'm going to be calling the sleep function 126 00:05:42,900 --> 00:05:44,490 for dramatic effect, 127 00:05:44,490 --> 00:05:47,100 and I'm going to use the duration structure 128 00:05:47,100 --> 00:05:49,713 to specify the duration of my sleeps. 129 00:05:50,640 --> 00:05:52,930 Okay, I've got a public 130 00:05:54,060 --> 00:05:56,613 global static called GLOBAL_MESSAGE. 131 00:05:57,539 --> 00:06:00,360 That's a simple string or string slice, 132 00:06:00,360 --> 00:06:04,650 I should say, initialized with some hard-coded text, 133 00:06:04,650 --> 00:06:05,483 that's quite easy, 134 00:06:05,483 --> 00:06:07,140 so this variable will be initialized 135 00:06:07,140 --> 00:06:10,304 by the compiler at compiler time. 136 00:06:10,304 --> 00:06:12,900 And because it's public, as well as being able to access it 137 00:06:12,900 --> 00:06:14,400 in this file, 138 00:06:14,400 --> 00:06:17,010 I could potentially access it elsewhere as well, 139 00:06:17,010 --> 00:06:18,840 so bear that in mind. 140 00:06:18,840 --> 00:06:22,740 And then, I've got another static, this one isn't public. 141 00:06:22,740 --> 00:06:25,544 So, I decided not to make it public. 142 00:06:25,544 --> 00:06:26,377 (keyboard keys clicking) 143 00:06:26,377 --> 00:06:29,130 So, it can only be accessed, it's kind of global, 144 00:06:29,130 --> 00:06:30,753 but only global to this file. 145 00:06:31,685 --> 00:06:34,350 Okay, so get access GLOBAL_MESSAGE anywhere 146 00:06:34,350 --> 00:06:37,170 across the entire application because it's public. 147 00:06:37,170 --> 00:06:39,570 But GLOBAL_TIMESTAMP, I can only access 148 00:06:39,570 --> 00:06:43,050 in the current module, because it's not public. 149 00:06:43,050 --> 00:06:46,590 And it's also going to be initialized at runtime, 150 00:06:46,590 --> 00:06:49,080 so we have to use this Lazy mechanism again. 151 00:06:49,080 --> 00:06:53,490 Use the Lazy wrapper, it'll eventually contain a DateTime 152 00:06:53,490 --> 00:06:55,413 for universal coordinated time. 153 00:06:56,910 --> 00:06:57,960 To initialize it, 154 00:06:57,960 --> 00:07:00,720 I provide a closure, same kind of thing as we saw before. 155 00:07:00,720 --> 00:07:03,660 This closure will be executed once, 156 00:07:03,660 --> 00:07:06,870 the first time we try to access this variable anywhere, 157 00:07:06,870 --> 00:07:09,780 this closure will be executed, 158 00:07:09,780 --> 00:07:12,150 and once only. 159 00:07:12,150 --> 00:07:15,090 And get the current time at runtime. 160 00:07:15,090 --> 00:07:17,400 A quick print line message to say 161 00:07:17,400 --> 00:07:21,150 that the global variable called GLOBAL_TIMESTAMP. 162 00:07:21,150 --> 00:07:24,570 And this is the current time, okay? 163 00:07:24,570 --> 00:07:29,160 Now is the current time after that. 164 00:07:29,160 --> 00:07:32,040 So, whatever the current time is, will be displayed here. 165 00:07:32,040 --> 00:07:34,200 And so, this print statement just shows 166 00:07:34,200 --> 00:07:36,570 that it has been initialized, 167 00:07:36,570 --> 00:07:38,520 and we'll only see that appearing once. 168 00:07:38,520 --> 00:07:41,070 No matter how many times we use this variable, 169 00:07:41,070 --> 00:07:44,130 this closure only gets executed the first time. 170 00:07:44,130 --> 00:07:47,490 So, only the first time we use this 171 00:07:47,490 --> 00:07:49,530 will we see this message appear. 172 00:07:49,530 --> 00:07:52,950 So, the time that or the DateTime that gets returned, 173 00:07:52,950 --> 00:07:55,773 that will be the value for my GLOBAL_TIMESTAMP. 174 00:07:57,180 --> 00:07:59,670 Right, so anyway, the entry point, if you like, 175 00:07:59,670 --> 00:08:01,950 for this demo is here. 176 00:08:01,950 --> 00:08:05,370 And I call function 1 a couple of times. 177 00:08:05,370 --> 00:08:08,250 And I call function 2 a couple of times. 178 00:08:08,250 --> 00:08:10,050 So, let's have a look at function 1. 179 00:08:11,700 --> 00:08:16,700 So, function 1 accesses the GLOBAL_MESSAGE, which is here. 180 00:08:17,460 --> 00:08:19,410 This is a GLOBAL_MESSAGE. 181 00:08:19,410 --> 00:08:22,380 And it also accesses the GLOBAL_TIMESTAMP. 182 00:08:22,380 --> 00:08:26,400 Remember, GLOBAL_TIMESTAMP was initialized dynamically, 183 00:08:26,400 --> 00:08:28,320 it's a Lazy object. 184 00:08:28,320 --> 00:08:31,710 We use the star to de-reference, to look inside 185 00:08:31,710 --> 00:08:34,230 the Lazy wrapper, to gimme the contents. 186 00:08:34,230 --> 00:08:37,170 A bit like C++ pointers being de-referenced. 187 00:08:37,170 --> 00:08:39,900 Give me the GLOBAL_TIMESTAMP. 188 00:08:39,900 --> 00:08:43,560 So if this is the first usage of GLOBAL_TIMESTAMP 189 00:08:43,560 --> 00:08:46,893 at this moment, it'll have to be evaluated. 190 00:08:48,060 --> 00:08:50,730 Okay, and this closure here will be executed 191 00:08:50,730 --> 00:08:53,670 to give me the value of the GLOBAL_TIMESTAMP. 192 00:08:53,670 --> 00:08:56,133 So, the first time I call f1, 193 00:08:56,970 --> 00:09:00,870 that will call the initialization block to run. 194 00:09:00,870 --> 00:09:02,700 To initialize for the first time. 195 00:09:02,700 --> 00:09:07,600 The second time I call f1, it's already been evaluated. 196 00:09:07,600 --> 00:09:09,300 So, the GLOBAL_MESSAGE will be the same. 197 00:09:09,300 --> 00:09:11,880 The GLOBAL_TIMESTAMP has already been evaluated. 198 00:09:11,880 --> 00:09:15,270 So, it won't call the lambda a second time 199 00:09:15,270 --> 00:09:17,160 because it has already been evaluated. 200 00:09:17,160 --> 00:09:18,780 That's why in my demo, 201 00:09:18,780 --> 00:09:20,730 I've called the function twice to show that 202 00:09:20,730 --> 00:09:25,730 on the first call, this Lazy initialization will occur. 203 00:09:25,770 --> 00:09:28,650 On the second call, the initialization's already happened, 204 00:09:28,650 --> 00:09:31,230 so just reuse the value at that point. 205 00:09:31,230 --> 00:09:35,160 And then f2, f2, similar kinda thing. 206 00:09:35,160 --> 00:09:37,500 And f2, I wanted to highlight the fact 207 00:09:37,500 --> 00:09:40,680 that this really is a global variable. 208 00:09:40,680 --> 00:09:42,480 You can access it in any function, 209 00:09:42,480 --> 00:09:45,203 I can access GLOBAL_MESSAGE and GLOBAL_TIMESTAMP 210 00:09:45,203 --> 00:09:47,710 in that function, and I can access GLOBAL_MESSAGE 211 00:09:48,694 --> 00:09:50,520 and GLOBAL_TIMESTAMP in this function as well, 212 00:09:50,520 --> 00:09:51,723 because it's a global! 213 00:09:52,920 --> 00:09:53,753 Right. 214 00:09:53,753 --> 00:09:57,960 And furthermore, because GLOBAL_MESSAGE is public, 215 00:09:57,960 --> 00:10:01,020 I could access GLOBAL_MESSAGE in other modules as well. 216 00:10:01,020 --> 00:10:05,040 Like in my root crate, if you go back to the main.rs. 217 00:10:05,040 --> 00:10:07,656 I'm gonna basically access GLOBAL_MESSAGE 218 00:10:07,656 --> 00:10:10,620 in my other module as well, in main. 219 00:10:10,620 --> 00:10:15,620 So, what I've done is, I've introduced it into scope. 220 00:10:15,960 --> 00:10:18,110 I said, basically, from demo_static_global, 221 00:10:19,020 --> 00:10:21,720 introduced the GLOBAL_MESSAGE into scope. 222 00:10:21,720 --> 00:10:23,970 And then down here, 223 00:10:23,970 --> 00:10:25,653 I access GLOBAL_MESSAGE. 224 00:10:27,240 --> 00:10:29,193 If I didn't have the use statement, 225 00:10:30,090 --> 00:10:31,860 and it wouldn't be the end of the world, 226 00:10:31,860 --> 00:10:35,760 it just means I would then have to explicitly qualify 227 00:10:35,760 --> 00:10:37,830 the symbol like that. 228 00:10:37,830 --> 00:10:39,990 Okay, which is also allowable, 229 00:10:39,990 --> 00:10:42,840 but starting to get a little bit verbose, really. 230 00:10:42,840 --> 00:10:47,220 So, let's just revert to the import statement here. 231 00:10:47,220 --> 00:10:50,580 Introduce into the current scope, that symbol. 232 00:10:50,580 --> 00:10:52,290 So, I can just access it locally. 233 00:10:52,290 --> 00:10:55,530 And because GLOBAL_MESSAGE was public, 234 00:10:55,530 --> 00:10:57,510 I'm allowed to do that. 235 00:10:57,510 --> 00:11:00,660 If GLOBAL_MESSAGE hadn't been public, 236 00:11:00,660 --> 00:11:02,520 then no matter how hard you try, 237 00:11:02,520 --> 00:11:03,960 you can't access it elsewhere, 238 00:11:03,960 --> 00:11:07,320 it really would just be private to this file in that case, 239 00:11:07,320 --> 00:11:09,240 so let's make it public again. 240 00:11:09,240 --> 00:11:11,520 Let's go back into main.rs. 241 00:11:11,520 --> 00:11:14,373 And let's invoke our demo, demo_static_global. 242 00:11:16,716 --> 00:11:17,549 (keyboard keys clicking) 243 00:11:17,549 --> 00:11:18,382 And come at that statement. 244 00:11:18,382 --> 00:11:19,590 And I'm gonna run the code. 245 00:11:23,165 --> 00:11:23,998 (keyboard keys clicking) 246 00:11:23,998 --> 00:11:24,831 I'll go run! 247 00:11:29,160 --> 00:11:30,960 So, let's have a look! 248 00:11:30,960 --> 00:11:33,030 Let's just trace our progress. 249 00:11:33,030 --> 00:11:35,703 So, in demo_static_global. 250 00:11:37,230 --> 00:11:38,190 And ooh! 251 00:11:38,190 --> 00:11:39,023 Actually, 252 00:11:41,400 --> 00:11:43,120 this is 253 00:11:44,310 --> 00:11:45,603 interesting. 254 00:11:47,400 --> 00:11:52,400 It has performed the initialization of my GLOBAL_TIMESTAMP. 255 00:11:56,580 --> 00:12:00,513 I'm gonna just run this again in case I've missed something. 256 00:12:01,800 --> 00:12:03,630 Yes, there we go, that's better. 257 00:12:03,630 --> 00:12:06,300 So, it comes in here, and it displays 258 00:12:06,300 --> 00:12:09,090 In demo_static_global::do_it(). 259 00:12:09,090 --> 00:12:10,650 Okay, so that's good. 260 00:12:10,650 --> 00:12:12,303 And then, we call f1. 261 00:12:14,143 --> 00:12:14,976 And f1. 262 00:12:14,976 --> 00:12:17,160 It prints the GLOBAL_MESSAGE. 263 00:12:17,160 --> 00:12:18,810 So, there's the GLOBAL_MESSAGE. 264 00:12:18,810 --> 00:12:20,490 This is a GLOBAL_MESSAGE. 265 00:12:20,490 --> 00:12:23,430 And then, it tries to access GLOBAL_TIMESTAMP. 266 00:12:23,430 --> 00:12:26,820 And because this is the first time we've tried to access it, 267 00:12:26,820 --> 00:12:28,530 Lazy initialization kicks in. 268 00:12:28,530 --> 00:12:33,530 So, at that point, it will invoke the lambda or the closure. 269 00:12:34,680 --> 00:12:39,390 And it'll say the GLOBAL_TIMESTAMP is being initialized now. 270 00:12:39,390 --> 00:12:42,210 So, that's the message here. 271 00:12:42,210 --> 00:12:44,340 That's only gonna appear the first time. 272 00:12:44,340 --> 00:12:48,850 Whatever it returns, that is the value of GLOBAL_TIMESTAMP. 273 00:12:48,850 --> 00:12:51,030 Okay, so we can forget that now. 274 00:12:51,030 --> 00:12:53,790 And it'll print the value for GLOBAL_TIMESTAMP. 275 00:12:53,790 --> 00:12:55,983 And that is the value for GLOBAL_TIMESTAMP. 276 00:12:57,210 --> 00:12:58,620 Okay, good. 277 00:12:58,620 --> 00:13:00,840 And then, we call f1 again. 278 00:13:00,840 --> 00:13:04,110 And this time, it'll just access the variables directly, 279 00:13:04,110 --> 00:13:06,540 without any need to run the closure again. 280 00:13:06,540 --> 00:13:09,360 So, in f1 this time, the GLOBAL_MESSAGE 281 00:13:09,360 --> 00:13:12,261 and the GLOBAL_TIMESTAMP, same as before. 282 00:13:12,261 --> 00:13:13,830 12:14:21. 283 00:13:13,830 --> 00:13:17,100 And then, when I call f2 once and twice, 284 00:13:17,100 --> 00:13:20,820 it'll also just reuse the existing variable. 285 00:13:20,820 --> 00:13:22,560 That variable has been initialized now, 286 00:13:22,560 --> 00:13:24,450 and it's the same as before. 287 00:13:24,450 --> 00:13:29,450 So in f2, GLOBAL_TIMESTAMP, GLOBAL_TIMESTAMP. 288 00:13:29,970 --> 00:13:34,970 At the end of my function here, I go back to main. 289 00:13:35,130 --> 00:13:36,333 And at the end of main, 290 00:13:37,290 --> 00:13:40,470 I just access the global variable from here as well. 291 00:13:40,470 --> 00:13:42,840 Okay? So, GLOBAL_MESSAGE really is global. 292 00:13:42,840 --> 00:13:46,110 And because it's public, I can access it in main as well. 293 00:13:46,110 --> 00:13:47,640 Okay, and it says, by the way, 294 00:13:47,640 --> 00:13:50,493 the GLOBAL_MESSAGE is this is a GLOBAL_MESSAGE. 295 00:13:51,340 --> 00:13:52,200 There we are. 296 00:13:52,200 --> 00:13:55,020 So, just to recap then, 297 00:13:55,020 --> 00:13:58,590 you can declare global variables in Rust. 298 00:13:58,590 --> 00:14:03,510 It's frowned upon because it kind of opens you up to misuse. 299 00:14:03,510 --> 00:14:06,060 You have to use the static keyword. 300 00:14:06,060 --> 00:14:07,470 And if you want to initialize it 301 00:14:07,470 --> 00:14:10,410 with a fixed value at compile time, it's easy. 302 00:14:10,410 --> 00:14:11,580 If you want to initialize it 303 00:14:11,580 --> 00:14:14,670 with some kind of computed value, it's not so easy, 304 00:14:14,670 --> 00:14:17,130 you basically have to use a Lazy wrapper, 305 00:14:17,130 --> 00:14:18,510 and have some code 306 00:14:18,510 --> 00:14:22,350 that can be executed thread safe by Rust 307 00:14:22,350 --> 00:14:25,533 the first time you try to access the to initialize it.