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

@ -1,29 +0,0 @@
use crate::{ShellError, Value};
impl Value {
pub fn as_f64(&self) -> Result<f64, ShellError> {
match self {
Value::Float { val, .. } => Ok(*val),
x => Err(ShellError::CantConvert {
to_type: "f64".into(),
from_type: x.get_type().to_string(),
span: self.span(),
help: None,
}),
}
}
pub fn as_i64(&self) -> Result<i64, ShellError> {
match self {
Value::Int { val, .. } => Ok(*val),
Value::Filesize { val, .. } => Ok(*val),
Value::Duration { val, .. } => Ok(*val),
x => Err(ShellError::CantConvert {
to_type: "i64".into(),
from_type: x.get_type().to_string(),
span: self.span(),
help: None,
}),
}
}
}

View File

@ -1,7 +1,6 @@
mod custom_value;
mod duration;
mod filesize;
mod from;
mod from_value;
mod glob;
mod into_value;