mirror of
https://github.com/nushell/nushell
synced 2024-12-27 05:23:11 +00:00
allow size
and other to count bytes from binary with as_string()
(#769)
This commit is contained in:
parent
01e691c5ba
commit
2c75aabbfc
1 changed files with 10 additions and 0 deletions
|
@ -172,6 +172,16 @@ impl Value {
|
|||
pub fn as_string(&self) -> Result<String, ShellError> {
|
||||
match self {
|
||||
Value::String { val, .. } => Ok(val.to_string()),
|
||||
Value::Binary { val, .. } => Ok(match std::str::from_utf8(val) {
|
||||
Ok(s) => s.to_string(),
|
||||
Err(_) => {
|
||||
return Err(ShellError::CantConvert(
|
||||
"binary".into(),
|
||||
"string".into(),
|
||||
self.span()?,
|
||||
))
|
||||
}
|
||||
}),
|
||||
x => Err(ShellError::CantConvert(
|
||||
"string".into(),
|
||||
x.get_type().to_string(),
|
||||
|
|
Loading…
Reference in a new issue