2020-03-03 11:15:18 +00:00
use crate ::{ Result , Scalar , Value } ;
2020-03-02 00:24:49 +00:00
macro_rules ! impl_float_scalars {
( $( $ty :ty ) , * ) = > {
$(
impl Scalar for $ty {
fn type_name ( ) -> & 'static str {
2020-03-03 11:15:18 +00:00
" Float "
2020-03-02 00:24:49 +00:00
}
2020-03-03 11:15:18 +00:00
fn description ( ) -> Option < & 'static str > {
Some ( " The `Float` scalar type represents signed double-precision fractional values as specified by [IEEE 754](https://en.wikipedia.org/wiki/IEEE_floating_point). " )
}
2020-03-04 02:38:07 +00:00
fn parse ( value : & Value ) -> Option < Self > {
2020-03-02 00:24:49 +00:00
match value {
2020-03-03 11:15:18 +00:00
Value ::Int ( n ) = > Some ( n . as_i64 ( ) . unwrap ( ) as Self ) ,
2020-03-04 02:38:07 +00:00
Value ::Float ( n ) = > Some ( * n as Self ) ,
2020-03-03 11:15:18 +00:00
_ = > None
2020-03-02 00:24:49 +00:00
}
}
fn to_json ( & self ) -> Result < serde_json ::Value > {
Ok ( ( * self ) . into ( ) )
}
}
) *
} ;
}
impl_float_scalars! ( f32 , f64 ) ;