1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
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(
"f64".into(),
x.get_type().to_string(),
self.span()?,
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(
"i64".into(),
x.get_type().to_string(),
self.span()?,
None,
)),
}
}
}