mirror of
https://github.com/nushell/nushell
synced 2025-01-09 03:39:03 +00:00
25 lines
658 B
Rust
25 lines
658 B
Rust
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()?,
|
|
)),
|
|
}
|
|
}
|
|
|
|
pub fn as_i64(&self) -> Result<i64, ShellError> {
|
|
match self {
|
|
Value::Int { val, .. } => Ok(*val),
|
|
x => Err(ShellError::CantConvert(
|
|
"rf64".into(),
|
|
x.get_type().to_string(),
|
|
self.span()?,
|
|
)),
|
|
}
|
|
}
|
|
}
|