Try to re-apply #1039

This commit is contained in:
Yehuda Katz
2019-12-02 08:14:05 -08:00
parent 8a0bdde17a
commit 4115634bfc
12 changed files with 151 additions and 213 deletions

View File

@ -1,7 +1,7 @@
use nu_errors::ShellError;
use crate::value::Value;
use derive_new::new;
use indexmap::IndexMap;
use nu_errors::ShellError;
use nu_source::Tag;
use serde::{Deserialize, Serialize};

View File

@ -1,5 +1,5 @@
use nu_errors::ShellError;
use crate::value::Value;
use nu_errors::ShellError;
use nu_source::{b, DebugDocBuilder, PrettyDebug};
use serde::{Deserialize, Serialize};

View File

@ -139,6 +139,13 @@ impl Value {
}
}
pub fn as_forgiving_string(&self) -> Result<&str, ShellError> {
match &self.value {
UntaggedValue::Primitive(Primitive::String(string)) => Ok(&string[..]),
_ => Err(ShellError::type_error("string", self.spanned_type_name())),
}
}
pub fn as_path(&self) -> Result<PathBuf, ShellError> {
match &self.value {
UntaggedValue::Primitive(Primitive::Path(path)) => Ok(path.clone()),

View File

@ -1,8 +1,8 @@
use nu_errors::{CoerceInto, ShellError};
use crate::type_name::SpannedTypeName;
use crate::value::dict::Dictionary;
use crate::value::primitive::Primitive;
use crate::value::{UntaggedValue, Value};
use nu_errors::{CoerceInto, ShellError};
use nu_source::TaggedItem;
impl std::convert::TryFrom<&Value> for i64 {