mirror of
https://github.com/nushell/nushell.git
synced 2025-06-30 22:50:14 +02:00
Add binary literals (#4680)
This commit is contained in:
@ -201,6 +201,7 @@ fn convert_to_value(
|
||||
"blocks not supported in nuon".into(),
|
||||
expr.span,
|
||||
)),
|
||||
Expr::Binary(val) => Ok(Value::Binary { val, span }),
|
||||
Expr::Bool(val) => Ok(Value::Bool { val, span }),
|
||||
Expr::Call(..) => Err(ShellError::OutsideSpannedLabeledError(
|
||||
original_text.to_string(),
|
||||
|
@ -1,3 +1,4 @@
|
||||
use core::fmt::Write;
|
||||
use nu_engine::get_columns;
|
||||
use nu_protocol::ast::{Call, RangeInclusion};
|
||||
use nu_protocol::engine::{Command, EngineState, Stack};
|
||||
@ -46,10 +47,18 @@ impl Command for ToNuon {
|
||||
|
||||
fn value_to_string(v: &Value, span: Span) -> Result<String, ShellError> {
|
||||
match v {
|
||||
Value::Binary { .. } => Err(ShellError::UnsupportedInput(
|
||||
"binary not supported".into(),
|
||||
span,
|
||||
)),
|
||||
Value::Binary { val, .. } => {
|
||||
let mut s = String::with_capacity(2 * val.len());
|
||||
for byte in val {
|
||||
if write!(s, "{:02X}", byte).is_err() {
|
||||
return Err(ShellError::UnsupportedInput(
|
||||
"binary could not translate to string".into(),
|
||||
span,
|
||||
));
|
||||
}
|
||||
}
|
||||
Ok(format!("0x[{}]", s))
|
||||
}
|
||||
Value::Block { .. } => Err(ShellError::UnsupportedInput(
|
||||
"block not supported".into(),
|
||||
span,
|
||||
|
Reference in New Issue
Block a user