Fix clippy warnings for into string command

This commit is contained in:
Stefan Stanciulescu 2021-11-02 20:51:03 +01:00
parent 070067b75e
commit 78cc3452df

View File

@ -1,15 +1,12 @@
use nu_protocol::Value::Filesize; use nu_engine::CallExt;
use nu_protocol::{ use nu_protocol::{
ast::Call, ast::Call,
engine::{Command, EngineState, Stack}, engine::{Command, EngineState, Stack},
Example, PipelineData, ShellError, Signature, Span, Spanned, SyntaxShape, Value, Example, PipelineData, ShellError, Signature, Span, SyntaxShape, Value,
}; };
use bigdecimal::{BigDecimal, FromPrimitive}; use bigdecimal::{BigDecimal, FromPrimitive};
use num_bigint::{BigInt, BigUint};
use nu_engine::CallExt;
use num_bigint::{BigInt, BigUint, ToBigInt};
use num_format::Locale; use num_format::Locale;
use num_traits::{Pow, Signed}; use num_traits::{Pow, Signed};
use std::iter; use std::iter;
@ -165,7 +162,7 @@ pub fn action(
group_digits: bool, group_digits: bool,
) -> Value { ) -> Value {
match input { match input {
Value::Int { val, span } => { Value::Int { val, span: _ } => {
let res = if group_digits { let res = if group_digits {
format_int(val) // int.to_formatted_string(*locale) format_int(val) // int.to_formatted_string(*locale)
} else { } else {
@ -177,18 +174,18 @@ pub fn action(
span: head, span: head,
} }
} }
Value::Float { val, span } => { Value::Float { val, span: _ } => {
if decimals { if decimals {
let dec = BigDecimal::from_f64(val); let dec = BigDecimal::from_f64(val);
let decimal_value = digits.unwrap() as u64; let decimal_value = digits.unwrap() as u64;
match dec { match dec {
Some(x) => Value::String { Some(x) => Value::String {
val: format_decimal(x, Some(decimal_value), group_digits), val: format_decimal(x, Some(decimal_value), group_digits),
span, span: head,
}, },
None => Value::Error { None => Value::Error {
error: ShellError::CantConvert( error: ShellError::CantConvert(
String::from(format!("cannot convert {}to BigDecimal", val)), format!("cannot convert {} to BigDecimal", val),
head, head,
), ),
}, },
@ -214,36 +211,33 @@ pub fn action(
// } // }
// .into_pipeline_data() // .into_pipeline_data()
// } // }
Value::Bool { val, span } => Value::String { Value::Bool { val, span: _ } => Value::String {
val: val.to_string(), val: val.to_string(),
span: head, span: head,
}, },
Value::Date { val, span } => Value::String { Value::Date { val, span: _ } => Value::String {
val: val.format("%c").to_string(), val: val.format("%c").to_string(),
span: head, span: head,
}, },
Value::String { val, span } => Value::String { val, span: head }, Value::String { val, span: _ } => Value::String { val, span: head },
// FIXME - we do not have a FilePath type anymore. Do we need to support this? // FIXME - we do not have a FilePath type anymore. Do we need to support this?
// Value::FilePath(a_filepath) => a_filepath.as_path().display().to_string(), // Value::FilePath(a_filepath) => a_filepath.as_path().display().to_string(),
Value::Filesize { val, span } => { Value::Filesize { val: _, span: _ } => Value::String {
// let byte_string = InlineShape::format_bytes(*val, None); val: input.into_string(),
// Ok(Value::String { span: head,
// val: byte_string.1, },
// span, Value::Nothing { span: _ } => Value::String {
// }
Value::String {
val: input.into_string(),
span: head,
}
}
Value::Nothing { span } => Value::String {
val: "nothing".to_string(), val: "nothing".to_string(),
span: head, span: head,
}, },
Value::Record { cols, vals, span } => Value::Error { Value::Record {
cols: _,
vals: _,
span: _,
} => Value::Error {
error: ShellError::UnsupportedInput( error: ShellError::UnsupportedInput(
"Cannot convert Record into string".to_string(), "Cannot convert Record into string".to_string(),
head, head,