feat(random): add random-decimal (#402)

This commit is contained in:
Jae-Heon Ji
2021-12-03 02:26:12 +09:00
committed by GitHub
parent f2aa952e86
commit 43972db131
4 changed files with 137 additions and 0 deletions

View File

@@ -203,6 +203,17 @@ impl Value {
}
}
pub fn as_float(&self) -> Result<f64, ShellError> {
match self {
Value::Float { val, .. } => Ok(*val),
x => Err(ShellError::CantConvert(
"float".into(),
x.get_type().to_string(),
self.span()?,
)),
}
}
/// Get the span for the current value
pub fn span(&self) -> Result<Span, ShellError> {
match self {
@@ -565,6 +576,10 @@ impl Value {
Value::Int { val, span }
}
pub fn float(val: f64, span: Span) -> Value {
Value::Float { val, span }
}
// Only use these for test data. Span::unknown() should not be used in user data
pub fn test_string(s: impl Into<String>) -> Value {
Value::String {