Reduce unwraps

Remove a number of unwraps. In some cases, a `?` just worked as is. I also made it possible to use `?` to go from Result<OutputStream, ShellError> to OutputStream. Finally, started updating PerItemCommand to be able to use the signature deserialization logic, which substantially reduces unwraps.

This is still in-progress work, but tests pass and it should be clear to merge and keep iterating on master.
This commit is contained in:
Yehuda Katz
2019-08-16 20:53:39 -07:00
parent 0dc4b2b686
commit 5bfb96447a
16 changed files with 240 additions and 101 deletions

View File

@ -7,12 +7,19 @@ use crate::shell::shell::Shell;
use rustyline::completion::FilenameCompleter;
use rustyline::hint::{Hinter, HistoryHinter};
use std::path::{Path, PathBuf};
pub struct FilesystemShell {
crate path: String,
completer: NuCompleter,
hinter: HistoryHinter,
}
impl std::fmt::Debug for FilesystemShell {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
write!(f, "FilesystemShell @ {}", self.path)
}
}
impl Clone for FilesystemShell {
fn clone(&self) -> Self {
FilesystemShell {

View File

@ -3,7 +3,7 @@ use crate::context::SourceMap;
use crate::errors::ShellError;
use crate::stream::OutputStream;
pub trait Shell {
pub trait Shell: std::fmt::Debug {
fn name(&self, source_map: &SourceMap) -> String;
fn ls(&self, args: EvaluatedWholeStreamCommandArgs) -> Result<OutputStream, ShellError>;
fn cd(&self, args: EvaluatedWholeStreamCommandArgs) -> Result<OutputStream, ShellError>;

View File

@ -7,7 +7,7 @@ use crate::stream::OutputStream;
use std::error::Error;
use std::sync::{Arc, Mutex};
#[derive(Clone)]
#[derive(Clone, Debug)]
pub struct ShellManager {
crate shells: Arc<Mutex<Vec<Box<dyn Shell + Send>>>>,
}

View File

@ -5,7 +5,7 @@ use crate::shell::shell::Shell;
use std::ffi::OsStr;
use std::path::PathBuf;
#[derive(Clone)]
#[derive(Clone, Debug)]
pub struct ValueShell {
crate path: String,
crate value: Tagged<Value>,