mirror of
https://github.com/nushell/nushell.git
synced 2025-08-09 12:25:58 +02:00
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:
@ -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 {
|
||||
|
Reference in New Issue
Block a user