Into binary changes (#3758)

* kind of works but not what we really want

* updated `into binary` and `first` to work better together

* attempt to fix wasm build problem

* attempt #2 to fix wasm stuff
This commit is contained in:
Darren Schroeder
2021-07-09 16:43:18 -05:00
committed by GitHub
parent 3262ffc1a6
commit 56c7a99eb4
6 changed files with 125 additions and 136 deletions

View File

@ -82,6 +82,11 @@ impl UntaggedValue {
}
}
/// Returns true if this value represents a binary
pub fn is_binary(&self) -> bool {
matches!(self, &UntaggedValue::Primitive(Primitive::Binary(_)))
}
/// Returns true if this value represents boolean true
pub fn is_true(&self) -> bool {
matches!(self, UntaggedValue::Primitive(Primitive::Boolean(true)))
@ -421,6 +426,14 @@ impl Value {
}
}
/// View a Primitive::Binary as a Vec<u8>, if possible
pub fn as_binary_vec(&self) -> Result<Vec<u8>, ShellError> {
match &self.value {
UntaggedValue::Primitive(Primitive::Binary(bin)) => Ok(bin.to_vec()),
_ => Err(ShellError::type_error("binary", self.spanned_type_name())),
}
}
/// View into the borrowed string contents of a Value, if possible
pub fn as_forgiving_string(&self) -> Result<&str, ShellError> {
match &self.value {