Simplify casting function signatures
This commit is contained in:
parent
bcaea757c2
commit
35010b21ae
1 changed files with 17 additions and 17 deletions
|
@ -3,70 +3,70 @@ use crate::err::Error;
|
||||||
use crate::sql::number::Number;
|
use crate::sql::number::Number;
|
||||||
use crate::sql::value::Value;
|
use crate::sql::value::Value;
|
||||||
|
|
||||||
pub fn run(ctx: &Context, name: &str, val: Value) -> Result<Value, Error> {
|
pub fn run(_: &Context, name: &str, val: Value) -> Result<Value, Error> {
|
||||||
match name {
|
match name {
|
||||||
"bool" => bool(ctx, val),
|
"bool" => bool(val),
|
||||||
"int" => int(ctx, val),
|
"int" => int(val),
|
||||||
"float" => float(ctx, val),
|
"float" => float(val),
|
||||||
"string" => string(ctx, val),
|
"string" => string(val),
|
||||||
"number" => number(ctx, val),
|
"number" => number(val),
|
||||||
"decimal" => decimal(ctx, val),
|
"decimal" => decimal(val),
|
||||||
"datetime" => datetime(ctx, val),
|
"datetime" => datetime(val),
|
||||||
"duration" => duration(ctx, val),
|
"duration" => duration(val),
|
||||||
_ => Ok(val),
|
_ => Ok(val),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn bool(_: &Context, val: Value) -> Result<Value, Error> {
|
pub fn bool(val: Value) -> Result<Value, Error> {
|
||||||
match val.is_truthy() {
|
match val.is_truthy() {
|
||||||
true => Ok(Value::True),
|
true => Ok(Value::True),
|
||||||
false => Ok(Value::False),
|
false => Ok(Value::False),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn int(_: &Context, val: Value) -> Result<Value, Error> {
|
pub fn int(val: Value) -> Result<Value, Error> {
|
||||||
match val {
|
match val {
|
||||||
Value::Number(Number::Int(_)) => Ok(val),
|
Value::Number(Number::Int(_)) => Ok(val),
|
||||||
_ => Ok(Value::Number(Number::Int(val.as_int()))),
|
_ => Ok(Value::Number(Number::Int(val.as_int()))),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn float(_: &Context, val: Value) -> Result<Value, Error> {
|
pub fn float(val: Value) -> Result<Value, Error> {
|
||||||
match val {
|
match val {
|
||||||
Value::Number(Number::Float(_)) => Ok(val),
|
Value::Number(Number::Float(_)) => Ok(val),
|
||||||
_ => Ok(Value::Number(Number::Float(val.as_float()))),
|
_ => Ok(Value::Number(Number::Float(val.as_float()))),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn number(_: &Context, val: Value) -> Result<Value, Error> {
|
pub fn number(val: Value) -> Result<Value, Error> {
|
||||||
match val {
|
match val {
|
||||||
Value::Number(Number::Decimal(_)) => Ok(val),
|
Value::Number(Number::Decimal(_)) => Ok(val),
|
||||||
_ => Ok(Value::Number(Number::Decimal(val.as_decimal()))),
|
_ => Ok(Value::Number(Number::Decimal(val.as_decimal()))),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn decimal(_: &Context, val: Value) -> Result<Value, Error> {
|
pub fn decimal(val: Value) -> Result<Value, Error> {
|
||||||
match val {
|
match val {
|
||||||
Value::Number(Number::Decimal(_)) => Ok(val),
|
Value::Number(Number::Decimal(_)) => Ok(val),
|
||||||
_ => Ok(Value::Number(Number::Decimal(val.as_decimal()))),
|
_ => Ok(Value::Number(Number::Decimal(val.as_decimal()))),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn string(_: &Context, val: Value) -> Result<Value, Error> {
|
pub fn string(val: Value) -> Result<Value, Error> {
|
||||||
match val {
|
match val {
|
||||||
Value::Strand(_) => Ok(val),
|
Value::Strand(_) => Ok(val),
|
||||||
_ => Ok(Value::Strand(val.as_strand())),
|
_ => Ok(Value::Strand(val.as_strand())),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn datetime(_: &Context, val: Value) -> Result<Value, Error> {
|
pub fn datetime(val: Value) -> Result<Value, Error> {
|
||||||
match val {
|
match val {
|
||||||
Value::Datetime(_) => Ok(val),
|
Value::Datetime(_) => Ok(val),
|
||||||
_ => Ok(Value::Datetime(val.as_datetime())),
|
_ => Ok(Value::Datetime(val.as_datetime())),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn duration(_: &Context, val: Value) -> Result<Value, Error> {
|
pub fn duration(val: Value) -> Result<Value, Error> {
|
||||||
match val {
|
match val {
|
||||||
Value::Duration(_) => Ok(val),
|
Value::Duration(_) => Ok(val),
|
||||||
_ => Ok(Value::Duration(val.as_duration())),
|
_ => Ok(Value::Duration(val.as_duration())),
|
||||||
|
|
Loading…
Reference in a new issue