mirror of
https://github.com/nushell/nushell.git
synced 2024-12-23 15:39:06 +01:00
allow size
and other to count bytes from binary with as_string()
(#769)
This commit is contained in:
parent
01e691c5ba
commit
2c75aabbfc
@ -172,6 +172,16 @@ impl Value {
|
|||||||
pub fn as_string(&self) -> Result<String, ShellError> {
|
pub fn as_string(&self) -> Result<String, ShellError> {
|
||||||
match self {
|
match self {
|
||||||
Value::String { val, .. } => Ok(val.to_string()),
|
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(
|
x => Err(ShellError::CantConvert(
|
||||||
"string".into(),
|
"string".into(),
|
||||||
x.get_type().to_string(),
|
x.get_type().to_string(),
|
||||||
|
Loading…
Reference in New Issue
Block a user