1 00:00:06,600 --> 00:00:09,390 - Okay, so I'm gonna close the code file. 2 00:00:09,390 --> 00:00:10,950 I'll just clap things down. 3 00:00:10,950 --> 00:00:13,140 I'm gonna give myself a bit more space 4 00:00:13,140 --> 00:00:14,760 in my terminal window, 5 00:00:14,760 --> 00:00:16,770 so we can actually see things a bit better. 6 00:00:16,770 --> 00:00:17,603 Cargo run. 7 00:00:20,370 --> 00:00:21,420 If this is the first time 8 00:00:21,420 --> 00:00:23,550 that you're running the application yourself, 9 00:00:23,550 --> 00:00:26,490 at this point, it'll probably spend about a minute 10 00:00:26,490 --> 00:00:29,520 downloading dependencies. 11 00:00:29,520 --> 00:00:31,350 I've already run this application before, 12 00:00:31,350 --> 00:00:32,970 so it just starts immediately. 13 00:00:32,970 --> 00:00:34,638 This is the menu. 14 00:00:34,638 --> 00:00:36,990 I can display all visits. 15 00:00:36,990 --> 00:00:39,180 Yes. Let's choose option one. 16 00:00:39,180 --> 00:00:43,230 Press enter and it's already read the data 17 00:00:43,230 --> 00:00:46,380 from the file into memory when the application started. 18 00:00:46,380 --> 00:00:47,370 So when I choose option one, 19 00:00:47,370 --> 00:00:50,103 it'll just display all the visits that it read in. 20 00:00:51,330 --> 00:00:52,163 There we go. 21 00:00:53,100 --> 00:00:55,950 Okay, so those are all the visits. 22 00:00:55,950 --> 00:01:00,450 Start date, end date, and the place name and description. 23 00:01:00,450 --> 00:01:02,100 And that was fairly straightforward. 24 00:01:02,100 --> 00:01:04,290 At the end, it then redisplays the menu. 25 00:01:04,290 --> 00:01:06,000 That's quite nice. 26 00:01:06,000 --> 00:01:10,950 So let's say this time or to calculate the visit days 27 00:01:10,950 --> 00:01:13,230 within a period of interest. 28 00:01:13,230 --> 00:01:16,293 What I was anxious about with this Brexit thing, 29 00:01:17,130 --> 00:01:20,520 if I book a course in three months' time, 30 00:01:20,520 --> 00:01:25,140 what will be my number of days at that point in time? 31 00:01:25,140 --> 00:01:27,660 So I'm okay now, but if I book these courses 32 00:01:27,660 --> 00:01:30,690 in like July, August, September, 33 00:01:30,690 --> 00:01:32,580 by the time it gets to the end of October, 34 00:01:32,580 --> 00:01:34,470 what's my number gonna look like then? 35 00:01:34,470 --> 00:01:36,150 Am I still less than 90? 36 00:01:36,150 --> 00:01:37,683 So if I choose option two, 37 00:01:39,360 --> 00:01:41,733 it says what reference date do you want to use? 38 00:01:42,690 --> 00:01:45,630 Like from when do you wanna start counting backwards? 39 00:01:45,630 --> 00:01:49,323 Well, today's date here is the 26th of May. 40 00:01:50,250 --> 00:01:51,660 So maybe I'll add to that. 41 00:01:51,660 --> 00:01:54,570 So it's year, year, year, then month, month, day, day. 42 00:01:54,570 --> 00:01:57,093 So 2023. 43 00:01:58,020 --> 00:02:03,020 The month is month five, and today's date is the 26th. 44 00:02:07,726 --> 00:02:08,790 I think it's the 25th actually. 45 00:02:08,790 --> 00:02:09,623 25th. 46 00:02:16,230 --> 00:02:18,873 Oh, so in that case, if you choose today, 47 00:02:19,920 --> 00:02:23,640 it'll only tell you, it doesn't tell you, you know, 48 00:02:23,640 --> 00:02:26,940 how many days you're on for previous days. 49 00:02:26,940 --> 00:02:28,890 Who cares what my day count was yesterday 50 00:02:28,890 --> 00:02:30,870 'cause yesterday's gone. 51 00:02:30,870 --> 00:02:33,270 So how about if I choose a date? 52 00:02:33,270 --> 00:02:36,150 I'll do the option again, option number two 53 00:02:36,150 --> 00:02:37,830 but I'll choose the end of the year, 54 00:02:37,830 --> 00:02:42,830 2023, December the 31st. 55 00:02:43,110 --> 00:02:48,110 So it'll display all the dates from there back to today. 56 00:02:49,380 --> 00:02:53,370 And it'll tell me for each date, what's my day count? 57 00:02:53,370 --> 00:02:56,580 So like from the 31st of December, 58 00:02:56,580 --> 00:02:59,400 if you go back 180 days from then, 59 00:02:59,400 --> 00:03:01,320 how many days was I in Europe? 60 00:03:01,320 --> 00:03:03,750 And then it'll say from the day before that, 61 00:03:03,750 --> 00:03:06,810 the 30th of December, how many days were you in Europe? 62 00:03:06,810 --> 00:03:08,730 And it'll do that backwards all the time 63 00:03:08,730 --> 00:03:10,130 until it gets back to today. 64 00:03:10,980 --> 00:03:12,123 So if I enter, 65 00:03:14,340 --> 00:03:17,010 all right, it actually displays two sets of information. 66 00:03:17,010 --> 00:03:18,330 When I first wrote the application, 67 00:03:18,330 --> 00:03:20,100 I realized it would actually be useful 68 00:03:20,100 --> 00:03:22,740 to see this information in two different ways. 69 00:03:22,740 --> 00:03:24,243 If I go back up to the top, 70 00:03:28,020 --> 00:03:30,020 we have lots of discussions about Brexit 71 00:03:30,960 --> 00:03:33,483 and none of them ever go well, to be honest. 72 00:03:34,800 --> 00:03:39,303 So I'm scrolling up to the top of the output. 73 00:03:41,130 --> 00:03:43,923 So it actually displays two blocks of information. 74 00:03:45,330 --> 00:03:49,113 First of all, it says from whatever date you specified, 75 00:03:49,950 --> 00:03:51,840 31st of December, 76 00:03:51,840 --> 00:03:55,650 at that point, if you look back for the previous 180 days, 77 00:03:55,650 --> 00:03:59,970 you'll have been away in that period 67 days. 78 00:03:59,970 --> 00:04:02,790 And then it says for the 30th of December, 79 00:04:02,790 --> 00:04:07,790 if you go back 180 days, you'll have been away 67 days. 80 00:04:07,800 --> 00:04:08,640 But if I scroll down, 81 00:04:08,640 --> 00:04:12,150 let's say I pick out the 3rd of December, my birthday, 82 00:04:12,150 --> 00:04:13,100 did I mention that? 83 00:04:14,010 --> 00:04:15,483 On the 3rd of December, 84 00:04:16,380 --> 00:04:19,620 if you look back the 180 days before that, 85 00:04:19,620 --> 00:04:22,470 you'd have been away 75 days. 86 00:04:22,470 --> 00:04:25,410 So this information, when I look at it, 87 00:04:25,410 --> 00:04:26,850 it gives me an indicator 88 00:04:26,850 --> 00:04:30,390 of where it's starting to get a bit close to 90, 89 00:04:30,390 --> 00:04:32,040 which I'm not allowed to go over. 90 00:04:33,254 --> 00:04:38,254 So a little bit scary actually here on the, oh, what's that? 91 00:04:39,690 --> 00:04:42,660 On the 4th of November, 92 00:04:42,660 --> 00:04:46,476 if you count from there backwards 180 days, 93 00:04:46,476 --> 00:04:49,323 I would've been away in Europe for 89 days. 94 00:04:50,520 --> 00:04:52,020 That's basically almost 90. 95 00:04:52,020 --> 00:04:53,880 I'd only have to have a overstay 96 00:04:53,880 --> 00:04:56,760 by one night because of storm. 97 00:04:56,760 --> 00:04:59,970 And I've only got one day margin, 98 00:04:59,970 --> 00:05:04,920 so I need to be careful booking courses that will, you know, 99 00:05:04,920 --> 00:05:08,073 around that date or within the period leading to that date. 100 00:05:09,810 --> 00:05:11,520 If I go back, what's the current day today? 101 00:05:11,520 --> 00:05:16,440 So we're currently on, well, let's pick the 1st of October, 102 00:05:16,440 --> 00:05:18,000 1st of August. 103 00:05:18,000 --> 00:05:22,980 On the 1st of August, in the 180 days previously, 104 00:05:22,980 --> 00:05:24,120 I'll have been away 74 days. 105 00:05:24,120 --> 00:05:25,173 So you get the idea. 106 00:05:26,130 --> 00:05:27,990 It tells you where the hotspots are. 107 00:05:27,990 --> 00:05:29,670 It tells me where I need to start being 108 00:05:29,670 --> 00:05:31,370 a bit more careful about bookings. 109 00:05:32,550 --> 00:05:35,080 What a sorry state of affairs this is, Brexit. 110 00:05:36,870 --> 00:05:38,310 I thought the other way would be useful, 111 00:05:38,310 --> 00:05:40,950 would be actually to show the dates, 112 00:05:40,950 --> 00:05:43,260 not from chronologically backwards, 113 00:05:43,260 --> 00:05:47,160 but in terms of the maximum number of days I was away. 114 00:05:47,160 --> 00:05:50,100 So the maximum of days was actually 89. 115 00:05:50,100 --> 00:05:54,120 And there were several days because I was away in a period, 116 00:05:54,120 --> 00:05:58,160 on each of these days, I'll have been away for 89 days 117 00:05:58,160 --> 00:06:00,750 in the previous 180. 118 00:06:00,750 --> 00:06:03,630 So it gives me a feeling for how close I am 119 00:06:03,630 --> 00:06:07,350 to the edge in terms of my allowance like that. 120 00:06:07,350 --> 00:06:08,670 So that displays the dates. 121 00:06:08,670 --> 00:06:10,710 The first output displayed the dates 122 00:06:10,710 --> 00:06:14,910 in reverse chronological order, and then the second output, 123 00:06:14,910 --> 00:06:16,380 the same data, but this time, 124 00:06:16,380 --> 00:06:19,180 displayed in reverse number of days that I've been away. 125 00:06:20,220 --> 00:06:22,140 So I can keep on top of it. 126 00:06:22,140 --> 00:06:23,910 There is actually an app I discovered 127 00:06:23,910 --> 00:06:28,773 that you can get on the iPhone or on a Galaxy, 128 00:06:29,700 --> 00:06:30,692 on an Android device 129 00:06:30,692 --> 00:06:33,540 that actually counts your Schengen visits for you. 130 00:06:33,540 --> 00:06:36,240 But it was a lot more fun writing a Rust application. 131 00:06:36,240 --> 00:06:38,550 Okay, so that's basically the data. 132 00:06:38,550 --> 00:06:40,200 I can add a visit. 133 00:06:40,200 --> 00:06:41,940 I'm not sure if I can actually, I think I'm full 134 00:06:41,940 --> 00:06:43,230 but I could add a visit potentially. 135 00:06:43,230 --> 00:06:44,700 That's option number three. 136 00:06:44,700 --> 00:06:47,670 Option number three, I've gotta enter the start-date 137 00:06:47,670 --> 00:06:49,740 and the end-date and the description. 138 00:06:49,740 --> 00:06:53,400 So let's say December looked pretty available. 139 00:06:53,400 --> 00:06:56,310 So let's say I go away on the, 140 00:06:56,310 --> 00:07:00,243 it's gonna be year, month, day format 2023, the 12th. 141 00:07:01,500 --> 00:07:04,170 December is usually a very busy month for training 142 00:07:04,170 --> 00:07:07,440 because a lot of companies have a budget for training, 143 00:07:07,440 --> 00:07:09,570 which expires at the end of the year 144 00:07:09,570 --> 00:07:12,780 and they have December to use the budget or lose it. 145 00:07:12,780 --> 00:07:17,310 So let's say I go away on the 10th of December 146 00:07:17,310 --> 00:07:22,310 and I come back on the 2023-12. 147 00:07:22,590 --> 00:07:23,520 It's usually for a week. 148 00:07:23,520 --> 00:07:25,680 So let's say the 18th of December, 149 00:07:25,680 --> 00:07:27,423 using one day exclusive. 150 00:07:28,710 --> 00:07:33,710 Visit to Lapland to see Santa. 151 00:07:36,240 --> 00:07:38,670 That was on the list several years ago 152 00:07:38,670 --> 00:07:40,650 when our children were littler. 153 00:07:40,650 --> 00:07:41,610 Didn't actually go though. 154 00:07:41,610 --> 00:07:43,413 A lot of money for one day. 155 00:07:44,610 --> 00:07:47,010 But anyway, I'm going for eight days. 156 00:07:47,010 --> 00:07:50,430 Okay, so that option has now been added into the list. 157 00:07:50,430 --> 00:07:54,660 And what I could do is I could choose option four 158 00:07:54,660 --> 00:07:59,660 to save that new data back to my file and then exit. 159 00:07:59,700 --> 00:08:03,270 Or I can choose option five to exit without saving. 160 00:08:03,270 --> 00:08:04,870 So I'm gonna choose option five. 161 00:08:05,911 --> 00:08:07,233 Like so. 162 00:08:08,520 --> 00:08:10,830 And then the application's finished. 163 00:08:10,830 --> 00:08:15,830 So as you can see, it's quite a useful application really. 164 00:08:16,200 --> 00:08:18,450 It's not the most complicated thing you'll ever see 165 00:08:18,450 --> 00:08:20,940 but it's complicated enough. 166 00:08:20,940 --> 00:08:23,760 Aspects of it, miscellaneous things, 167 00:08:23,760 --> 00:08:25,350 date handling, string handling, 168 00:08:25,350 --> 00:08:28,650 getting input from the user, utility stuff. 169 00:08:28,650 --> 00:08:33,270 Obviously, file handling, displaying menus and looping 170 00:08:33,270 --> 00:08:35,880 and a bit of date handling as well. 171 00:08:35,880 --> 00:08:39,270 So now that you know how the application works 172 00:08:39,270 --> 00:08:42,690 in terms of the functionality that it gives, 173 00:08:42,690 --> 00:08:44,340 what we're gonna do for the rest of the lesson 174 00:08:44,340 --> 00:08:45,420 is dive into the code 175 00:08:45,420 --> 00:08:47,970 and see the details of how it actually achieves it.