When app_state is AppState::ShouldQuit, the app need not have any data.
The above code become like this:
Model {
app_state: AppState::ShouldQuit,
}
Good effect of this change
This makes some good effect:
1. Improve readability
It made readability improved because the data structure describes the application state more precisely.
This may good especially for the person who are new to this project too.
2. Reduce the chance of potential bugs because invalid data accesses can't happen.
As the title says.
3. Remove unnecessary data for testing.
This is not huge advantage for now, but the effort for testing will not increase even though the data structure grows.
// Before
Case {
title: "Quit",
model: init_model(),
message: Some(Message::Quit),
expect_model: Model {
app_state: AppState::ShouldQuit,
..init_model() // this is unnecessary data
},
},
// After
Case {
title: "Quit",
model: Model {
app_state: AppState::SelectTarget(SelectTargetState {
..SelectTargetState::new_for_test()
}),
},
message: Some(Message::Quit),
expect_model: Model {
app_state: AppState::ShouldQuit,
},
},
Minor changes
Improve cohesiveness by extract logics to method.
Improve ordering of type definition and thier methods in app.rs.
Motivation
What's changed
Made impossible states impossible.
At first, I show main change point.
Before
After
By this change, we can no longer express impossible states like below.
When
app_state
isAppState::ShouldQuit
, the app need not have any data.The above code become like this:
Good effect of this change
This makes some good effect:
1. Improve readability
It made readability improved because the data structure describes the application state more precisely.
This may good especially for the person who are new to this project too.
2. Reduce the chance of potential bugs because invalid data accesses can't happen.
As the title says.
3. Remove unnecessary data for testing.
This is not huge advantage for now, but the effort for testing will not increase even though the data structure grows.
Minor changes
app.rs
.