Remove as_i64 and as_f64 (#14258)

# Description
Turns out there are duplicate conversion functions: `as_i64` and
`as_f64`. In most cases, these can be replaced with `as_int` and
`as_float`, respectively.
This commit is contained in:
Ian Manske
2024-11-05 00:28:56 -08:00
committed by GitHub
parent 1e051e573d
commit e87a35104a
9 changed files with 33 additions and 61 deletions

View File

@ -259,7 +259,7 @@ fn action(input: &Value, args: &Arguments, span: Span) -> Value {
if radix == 10 {
*val as i64
} else {
match convert_int(&Value::int(*val as i64, span), span, radix).as_i64() {
match convert_int(&Value::int(*val as i64, span), span, radix).as_int() {
Ok(v) => v,
_ => {
return Value::error(

View File

@ -1,5 +1,6 @@
use chrono::{Duration, Local, NaiveDate};
use nu_engine::command_prelude::*;
use nu_protocol::FromValue;
use std::fmt::Write;
@ -187,13 +188,14 @@ pub fn run_seq_dates(
) -> Result<Value, ShellError> {
let today = Local::now().date_naive();
// if cannot convert , it will return error
let mut step_size: i64 = increment.as_i64()?;
let increment_span = increment.span();
let mut step_size: i64 = i64::from_value(increment)?;
if step_size == 0 {
return Err(ShellError::GenericError {
error: "increment cannot be 0".into(),
msg: "increment cannot be 0".into(),
span: Some(increment.span()),
span: Some(increment_span),
help: None,
inner: vec![],
});
@ -264,7 +266,7 @@ pub fn run_seq_dates(
};
let mut days_to_output = match day_count {
Some(d) => d.as_i64()?,
Some(d) => i64::from_value(d)?,
None => 0i64,
};