2021-12-19 07:46:13 +00:00
|
|
|
use crate::{ShellError, Value};
|
2021-11-23 08:14:40 +00:00
|
|
|
|
|
|
|
impl Value {
|
|
|
|
pub fn as_f64(&self) -> Result<f64, ShellError> {
|
|
|
|
match self {
|
|
|
|
Value::Float { val, .. } => Ok(*val),
|
|
|
|
x => Err(ShellError::CantConvert(
|
|
|
|
"f64".into(),
|
|
|
|
x.get_type().to_string(),
|
|
|
|
self.span()?,
|
2022-04-18 12:34:10 +00:00
|
|
|
None,
|
2021-11-23 08:14:40 +00:00
|
|
|
)),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn as_i64(&self) -> Result<i64, ShellError> {
|
|
|
|
match self {
|
|
|
|
Value::Int { val, .. } => Ok(*val),
|
2022-06-13 19:44:32 +00:00
|
|
|
Value::Filesize { val, .. } => Ok(*val),
|
|
|
|
Value::Duration { val, .. } => Ok(*val),
|
2021-11-23 08:14:40 +00:00
|
|
|
x => Err(ShellError::CantConvert(
|
2022-03-24 12:04:31 +00:00
|
|
|
"i64".into(),
|
2021-11-23 08:14:40 +00:00
|
|
|
x.get_type().to_string(),
|
|
|
|
self.span()?,
|
2022-04-18 12:34:10 +00:00
|
|
|
None,
|
2021-11-23 08:14:40 +00:00
|
|
|
)),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|