Change using Result
This commit is contained in:
13
src/app.rs
13
src/app.rs
@@ -24,13 +24,13 @@ pub(crate) struct App {
|
||||
}
|
||||
|
||||
impl App {
|
||||
pub fn new() -> App {
|
||||
pub fn new() -> Self {
|
||||
let app_conf =
|
||||
if APP_CONIFG_FILE_PATH.exists() { ApplicationConfig::from_file(&APP_CONIFG_FILE_PATH) }
|
||||
if APP_CONIFG_FILE_PATH.exists() { ApplicationConfig::from_file(&APP_CONIFG_FILE_PATH).unwrap() }
|
||||
else { ApplicationConfig::new() };
|
||||
Self::initialize();
|
||||
let db_conn = Self::establish_db_connection(app_conf.clone());
|
||||
App {
|
||||
Self {
|
||||
running: true,
|
||||
events: EventHandler::new(Duration::from_millis(app_conf.basic_config.tick_rate)),
|
||||
db_connection: db_conn,
|
||||
@@ -67,7 +67,7 @@ impl App {
|
||||
fn update(&mut self, event: Event) -> Result<()> {
|
||||
if let Event::Key(key) = event && event::KeyEventKind::is_press(&key.kind) {
|
||||
match key.code {
|
||||
Char('q') => self.quit(),
|
||||
Char('q') => self.quit()?,
|
||||
_ => {}
|
||||
}
|
||||
}
|
||||
@@ -129,10 +129,11 @@ impl App {
|
||||
|
||||
// event handlers
|
||||
impl App {
|
||||
fn quit(&mut self) {
|
||||
fn quit(&mut self) -> Result<()> {
|
||||
self.running = false;
|
||||
self.app_config
|
||||
.clone()
|
||||
.write_to_file(APP_CONIFG_FILE_PATH.to_path_buf());
|
||||
.write_to_file(APP_CONIFG_FILE_PATH.to_path_buf())?;
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user