mirror of
https://github.com/nushell/nushell.git
synced 2025-08-09 14:15:53 +02:00
Convert the rest of "random" subcommands to engine-p (#3399)
* Convert "random bool" to engine-p Also implements FromValue for Tagged<BigDecimal> and Tagged<f64>. * Convert "random dice" to engine-p * Convert "random uuid" to engine-p * Covert "random chars" to engine-p * Convert "random" command to engine-p
This commit is contained in:
@ -1,5 +1,6 @@
|
||||
use std::path::PathBuf;
|
||||
|
||||
use bigdecimal::ToPrimitive;
|
||||
use chrono::{DateTime, FixedOffset};
|
||||
use nu_errors::ShellError;
|
||||
use nu_protocol::{
|
||||
@ -116,6 +117,36 @@ impl FromValue for bigdecimal::BigDecimal {
|
||||
}
|
||||
}
|
||||
|
||||
impl FromValue for Tagged<bigdecimal::BigDecimal> {
|
||||
fn from_value(v: &Value) -> Result<Self, ShellError> {
|
||||
let tag = v.tag.clone();
|
||||
match &v.value {
|
||||
UntaggedValue::Primitive(Primitive::Decimal(d)) => Ok(d.clone().tagged(tag)),
|
||||
_ => Err(ShellError::labeled_error(
|
||||
"Can't convert to decimal",
|
||||
"can't convert to decimal",
|
||||
tag.span,
|
||||
)),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl FromValue for Tagged<f64> {
|
||||
fn from_value(v: &Value) -> Result<Self, ShellError> {
|
||||
let tag = v.tag.clone();
|
||||
let decimal: bigdecimal::BigDecimal = FromValue::from_value(v)?;
|
||||
|
||||
match decimal.to_f64() {
|
||||
Some(d) => Ok(d.tagged(tag)),
|
||||
None => Err(ShellError::labeled_error(
|
||||
"Can't convert to decimal",
|
||||
"can't convert to decimal",
|
||||
tag.span,
|
||||
)),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl FromValue for String {
|
||||
fn from_value(v: &Value) -> Result<Self, ShellError> {
|
||||
match v {
|
||||
|
Reference in New Issue
Block a user