- Okay, so I'm gonna close the code file.
I'll just clap things down.
I'm gonna give myself a bit more space
in my terminal window,
so we can actually see things a bit better.
Cargo run.
If this is the first time
that you're running the application yourself,
at this point, it'll probably spend about a minute
downloading dependencies.
I've already run this application before,
so it just starts immediately.
This is the menu.
I can display all visits.
Yes. Let's choose option one.
Press enter and it's already read the data
from the file into memory when the application started.
So when I choose option one,
it'll just display all the visits that it read in.
There we go.
Okay, so those are all the visits.
Start date, end date, and the place name and description.
And that was fairly straightforward.
At the end, it then redisplays the menu.
That's quite nice.
So let's say this time or to calculate the visit days
within a period of interest.
What I was anxious about with this Brexit thing,
if I book a course in three months' time,
what will be my number of days at that point in time?
So I'm okay now, but if I book these courses
in like July, August, September,
by the time it gets to the end of October,
what's my number gonna look like then?
Am I still less than 90?
So if I choose option two,
it says what reference date do you want to use?
Like from when do you wanna start counting backwards?
Well, today's date here is the 26th of May.
So maybe I'll add to that.
So it's year, year, year, then month, month, day, day.
So 2023.
The month is month five, and today's date is the 26th.
I think it's the 25th actually.
25th.
Oh, so in that case, if you choose today,
it'll only tell you, it doesn't tell you, you know,
how many days you're on for previous days.
Who cares what my day count was yesterday
'cause yesterday's gone.
So how about if I choose a date?
I'll do the option again, option number two
but I'll choose the end of the year,
2023, December the 31st.
So it'll display all the dates from there back to today.
And it'll tell me for each date, what's my day count?
So like from the 31st of December,
if you go back 180 days from then,
how many days was I in Europe?
And then it'll say from the day before that,
the 30th of December, how many days were you in Europe?
And it'll do that backwards all the time
until it gets back to today.
So if I enter,
all right, it actually displays two sets of information.
When I first wrote the application,
I realized it would actually be useful
to see this information in two different ways.
If I go back up to the top,
we have lots of discussions about Brexit
and none of them ever go well, to be honest.
So I'm scrolling up to the top of the output.
So it actually displays two blocks of information.
First of all, it says from whatever date you specified,
31st of December,
at that point, if you look back for the previous 180 days,
you'll have been away in that period 67 days.
And then it says for the 30th of December,
if you go back 180 days, you'll have been away 67 days.
But if I scroll down,
let's say I pick out the 3rd of December, my birthday,
did I mention that?
On the 3rd of December,
if you look back the 180 days before that,
you'd have been away 75 days.
So this information, when I look at it,
it gives me an indicator
of where it's starting to get a bit close to 90,
which I'm not allowed to go over.
So a little bit scary actually here on the, oh, what's that?
On the 4th of November,
if you count from there backwards 180 days,
I would've been away in Europe for 89 days.
That's basically almost 90.
I'd only have to have a overstay
by one night because of storm.
And I've only got one day margin,
so I need to be careful booking courses that will, you know,
around that date or within the period leading to that date.
If I go back, what's the current day today?
So we're currently on, well, let's pick the 1st of October,
1st of August.
On the 1st of August, in the 180 days previously,
I'll have been away 74 days.
So you get the idea.
It tells you where the hotspots are.
It tells me where I need to start being
a bit more careful about bookings.
What a sorry state of affairs this is, Brexit.
I thought the other way would be useful,
would be actually to show the dates,
not from chronologically backwards,
but in terms of the maximum number of days I was away.
So the maximum of days was actually 89.
And there were several days because I was away in a period,
on each of these days, I'll have been away for 89 days
in the previous 180.
So it gives me a feeling for how close I am
to the edge in terms of my allowance like that.
So that displays the dates.
The first output displayed the dates
in reverse chronological order, and then the second output,
the same data, but this time,
displayed in reverse number of days that I've been away.
So I can keep on top of it.
There is actually an app I discovered
that you can get on the iPhone or on a Galaxy,
on an Android device
that actually counts your Schengen visits for you.
But it was a lot more fun writing a Rust application.
Okay, so that's basically the data.
I can add a visit.
I'm not sure if I can actually, I think I'm full
but I could add a visit potentially.
That's option number three.
Option number three, I've gotta enter the start-date
and the end-date and the description.
So let's say December looked pretty available.
So let's say I go away on the,
it's gonna be year, month, day format 2023, the 12th.
December is usually a very busy month for training
because a lot of companies have a budget for training,
which expires at the end of the year
and they have December to use the budget or lose it.
So let's say I go away on the 10th of December
and I come back on the 2023-12.
It's usually for a week.
So let's say the 18th of December,
using one day exclusive.
Visit to Lapland to see Santa.
That was on the list several years ago
when our children were littler.
Didn't actually go though.
A lot of money for one day.
But anyway, I'm going for eight days.
Okay, so that option has now been added into the list.
And what I could do is I could choose option four
to save that new data back to my file and then exit.
Or I can choose option five to exit without saving.
So I'm gonna choose option five.
Like so.
And then the application's finished.
So as you can see, it's quite a useful application really.
It's not the most complicated thing you'll ever see
but it's complicated enough.
Aspects of it, miscellaneous things,
date handling, string handling,
getting input from the user, utility stuff.
Obviously, file handling, displaying menus and looping
and a bit of date handling as well.
So now that you know how the application works
in terms of the functionality that it gives,
what we're gonna do for the rest of the lesson
is dive into the code
and see the details of how it actually achieves it.