PoC in Rust Loading State from disk on crash
This commit is contained in:
parent
8c796b1590
commit
2e84b06a91
@ -6,6 +6,7 @@ use iced::widget::{center, column, row, text};
|
|||||||
use iced::{Element, Subscription, Theme, Center, Task};
|
use iced::{Element, Subscription, Theme, Center, Task};
|
||||||
use tokio::fs::File;
|
use tokio::fs::File;
|
||||||
use tokio::io::AsyncWriteExt;
|
use tokio::io::AsyncWriteExt;
|
||||||
|
use std::fs::read_to_string;
|
||||||
|
|
||||||
mod card_reader;
|
mod card_reader;
|
||||||
mod approx_time;
|
mod approx_time;
|
||||||
@ -31,7 +32,7 @@ struct State{
|
|||||||
impl Default for State {
|
impl Default for State {
|
||||||
fn default() -> Self {
|
fn default() -> Self {
|
||||||
Self {
|
Self {
|
||||||
racers: vec![RacerTime{time: Instant::now(), racer: Racer{starting_number:11,racer_id: 0, card_id: 0}}],
|
racers: vec![RacerTime{time: Instant::now(), racer: Racer{starting_number:11, card_id: 0}}],
|
||||||
db: Default::default(),
|
db: Default::default(),
|
||||||
time: Instant::now(),
|
time: Instant::now(),
|
||||||
}
|
}
|
||||||
@ -154,8 +155,9 @@ impl std::fmt::Debug for Message {
|
|||||||
|
|
||||||
|
|
||||||
pub fn main() -> iced::Result {
|
pub fn main() -> iced::Result {
|
||||||
|
let init_state = || -> State {read_to_string("state.json").ok().map(|s| serde_json::from_str(&s).ok()).flatten().unwrap_or_else(||Default::default())} ;
|
||||||
env_logger::init();
|
env_logger::init();
|
||||||
iced::application(State::default, State::update, State::view)
|
iced::application(init_state, State::update, State::view)
|
||||||
.subscription(State::subscription)
|
.subscription(State::subscription)
|
||||||
.theme(State::theme)
|
.theme(State::theme)
|
||||||
.run()
|
.run()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user