diff options
author | Jiayi Zhao <jeff.no.zhao@gmail.com> | 2019-06-29 22:30:26 -0400 |
---|---|---|
committer | Jiayi Zhao <jeff.no.zhao@gmail.com> | 2019-06-29 22:30:26 -0400 |
commit | 9a082fe7f0633593a6e07feb404f6434bb944511 (patch) | |
tree | d63c004684793a21e82921d0416d2d1471bf8b45 /src | |
parent | 5769d9df46c824de7e8e3e25281a1b6f6970b442 (diff) |
code cleanup
Diffstat (limited to 'src')
-rw-r--r-- | src/commands/change_directory.rs | 2 | ||||
-rw-r--r-- | src/commands/open_file.rs | 10 | ||||
-rw-r--r-- | src/commands/parent_directory.rs | 8 | ||||
-rw-r--r-- | src/commands/tab_operations.rs | 14 | ||||
-rw-r--r-- | src/commands/tab_switch.rs | 8 |
5 files changed, 16 insertions, 26 deletions
diff --git a/src/commands/change_directory.rs b/src/commands/change_directory.rs index 330c8b2..04c8973 100644 --- a/src/commands/change_directory.rs +++ b/src/commands/change_directory.rs @@ -25,7 +25,7 @@ impl ChangeDirectory { path: &path::PathBuf, context: &mut JoshutoContext, view: &JoshutoView, - ) -> Result<(), std::io::Error> { + ) -> std::io::Result<()> { let curr_tab = &mut context.tabs[context.curr_tab_index]; std::env::set_current_dir(path.as_path())?; diff --git a/src/commands/open_file.rs b/src/commands/open_file.rs index 42142a9..e698913 100644 --- a/src/commands/open_file.rs +++ b/src/commands/open_file.rs @@ -3,7 +3,7 @@ use std::path::{Path, PathBuf}; use crate::commands::{JoshutoCommand, JoshutoRunnable}; use crate::config::mimetype; use crate::context::JoshutoContext; -use crate::error::{JoshutoError, JoshutoResult}; +use crate::error::JoshutoResult; use crate::history::DirectoryHistory; use crate::textfield::JoshutoTextField; use crate::ui; @@ -37,7 +37,7 @@ impl OpenFile { mimetype_options } - fn open(context: &mut JoshutoContext, view: &JoshutoView) -> Result<(), std::io::Error> { + fn open(context: &mut JoshutoContext, view: &JoshutoView) -> std::io::Result<()> { let mut path: Option<PathBuf> = None; { let curr_list = &context.tabs[context.curr_tab_index].curr_list; @@ -120,10 +120,8 @@ impl std::fmt::Display for OpenFile { impl JoshutoRunnable for OpenFile { fn execute(&self, context: &mut JoshutoContext, view: &JoshutoView) -> JoshutoResult<()> { - match Self::open(context, view) { - Ok(_) => Ok(()), - Err(e) => Err(JoshutoError::from(e)), - } + Self::open(context, view)?; + Ok(()) } } diff --git a/src/commands/parent_directory.rs b/src/commands/parent_directory.rs index f0f690d..e514f94 100644 --- a/src/commands/parent_directory.rs +++ b/src/commands/parent_directory.rs @@ -1,6 +1,6 @@ use crate::commands::{JoshutoCommand, JoshutoRunnable}; use crate::context::JoshutoContext; -use crate::error::{JoshutoError, JoshutoResult}; +use crate::error::JoshutoResult; use crate::history::DirectoryHistory; use crate::window::JoshutoView; @@ -50,9 +50,7 @@ impl std::fmt::Display for ParentDirectory { impl JoshutoRunnable for ParentDirectory { fn execute(&self, context: &mut JoshutoContext, view: &JoshutoView) -> JoshutoResult<()> { - match Self::parent_directory(context, view) { - Ok(_) => Ok(()), - Err(e) => Err(JoshutoError::from(e)), - } + Self::parent_directory(context, view)?; + Ok(()) } } diff --git a/src/commands/tab_operations.rs b/src/commands/tab_operations.rs index 9b8c4fb..4d80732 100644 --- a/src/commands/tab_operations.rs +++ b/src/commands/tab_operations.rs @@ -2,7 +2,7 @@ use std::path; use crate::commands::{JoshutoCommand, JoshutoRunnable, Quit, TabSwitch}; use crate::context::JoshutoContext; -use crate::error::{JoshutoError, JoshutoResult}; +use crate::error::JoshutoResult; use crate::tab::JoshutoTab; use crate::window::JoshutoView; @@ -29,10 +29,8 @@ impl NewTab { let tab = JoshutoTab::new(curr_path, &context.config_t.sort_option)?; context.tabs.push(tab); context.curr_tab_index = context.tabs.len() - 1; - match TabSwitch::tab_switch(context.curr_tab_index, context, view) { - Ok(_) => Ok(()), - Err(e) => Err(JoshutoError::from(e)), - } + TabSwitch::tab_switch(context.curr_tab_index, context, view)?; + Ok(()) } } @@ -70,10 +68,8 @@ impl CloseTab { if context.curr_tab_index > 0 { context.curr_tab_index -= 1; } - match TabSwitch::tab_switch(context.curr_tab_index, context, view) { - Ok(_) => Ok(()), - Err(e) => Err(JoshutoError::from(e)), - } + TabSwitch::tab_switch(context.curr_tab_index, context, view)?; + Ok(()) } } diff --git a/src/commands/tab_switch.rs b/src/commands/tab_switch.rs index 4f927d7..f1adaa3 100644 --- a/src/commands/tab_switch.rs +++ b/src/commands/tab_switch.rs @@ -2,7 +2,7 @@ use std::env; use crate::commands::{JoshutoCommand, JoshutoRunnable}; use crate::context::JoshutoContext; -use crate::error::{JoshutoError, JoshutoResult}; +use crate::error::JoshutoResult; use crate::ui; use crate::window::JoshutoView; @@ -61,9 +61,7 @@ impl JoshutoRunnable for TabSwitch { new_index -= tab_len; } let new_index = new_index as usize; - match Self::tab_switch(new_index, context, view) { - Ok(_) => Ok(()), - Err(e) => Err(JoshutoError::from(e)), - } + Self::tab_switch(new_index, context, view)?; + Ok(()) } } |