mirror of
https://github.com/nushell/nushell.git
synced 2025-08-09 12:25:58 +02:00
feat(random): add random-decimal (#402)
This commit is contained in:
@ -80,6 +80,10 @@ pub enum ShellError {
|
||||
#[diagnostic(code(nu::shell::invalid_probability), url(docsrs))]
|
||||
InvalidProbability(#[label = "invalid probability"] Span),
|
||||
|
||||
#[error("Invalid range {0}..{1}")]
|
||||
#[diagnostic(code(nu::shell::invalid_range), url(docsrs))]
|
||||
InvalidRange(String, String, #[label = "expected a valid range"] Span),
|
||||
|
||||
#[error("Internal error: {0}.")]
|
||||
#[diagnostic(code(nu::shell::internal_error), url(docsrs))]
|
||||
InternalError(String),
|
||||
|
@ -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 {
|
||||
|
Reference in New Issue
Block a user