pub fn from_datum(datum: Datum, typ: &ScalarType) -> Option<Value> {
        match (datum, typ) {
            (Datum::Null, _) => None,
            (Datum::True, ScalarType::Bool) => Some(Value::Bool(true)),
            (Datum::False, ScalarType::Bool) => Some(Value::Bool(false)),
            (Datum::Int16(i), ScalarType::Int16) => Some(Value::Int2(i)),
            (Datum::Int32(i), ScalarType::Int32) => Some(Value::Int4(i)),
            (Datum::Int32(i), ScalarType::Oid) => Some(Value::Int4(i)),
            (Datum::Int32(i), ScalarType::RegClass) => Some(Value::Int4(i)),
            (Datum::Int32(i), ScalarType::RegProc) => Some(Value::Int4(i)),
            (Datum::Int32(i), ScalarType::RegType) => Some(Value::Int4(i)),
            (Datum::Int64(i), ScalarType::Int64) => Some(Value::Int8(i)),
            (Datum::Float32(f), ScalarType::Float32) => Some(Value::Float4(*f)),
            (Datum::Float64(f), ScalarType::Float64) => Some(Value::Float8(*f)),
            (Datum::Numeric(mut d), ScalarType::Numeric { scale }) => {
                if let Some(scale) = scale {
                    adt_numeric::rescale(&mut d.0, *scale).unwrap();
                }
                Some(Value::Numeric(Numeric(d)))
            }
            (Datum::Date(d), ScalarType::Date) => Some(Value::Date(d)),
            (Datum::Time(t), ScalarType::Time) => Some(Value::Time(t)),
            (Datum::Timestamp(ts), ScalarType::Timestamp) => Some(Value::Timestamp(ts)),
            (Datum::TimestampTz(ts), ScalarType::TimestampTz) => Some(Value::TimestampTz(ts)),
            (Datum::Interval(iv), ScalarType::Interval) => Some(Value::Interval(Interval(iv))),
            (Datum::Bytes(b), ScalarType::Bytes) => Some(Value::Bytea(b.to_vec())),
            (Datum::String(s), ScalarType::String) => Some(Value::Text(s.to_owned())),
            (Datum::String(s), ScalarType::VarChar { .. }) => Some(Value::VarChar(s.to_owned())),
            (Datum::String(s), ScalarType::Char { length }) => Some(Value::Char {
                inner: s.to_owned(),
                length: *length,
            }),
            (_, ScalarType::Jsonb) => {
                Some(Value::Jsonb(Jsonb(JsonbRef::from_datum(datum).to_owned())))
            }
            (Datum::Uuid(u), ScalarType::Uuid) => Some(Value::Uuid(u)),
            (Datum::Array(array), ScalarType::Array(elem_type)) => {
                let dims = array.dims().into_iter().collect();
                let elements = array
                    .elements()
                    .iter()
                    .map(|elem| Value::from_datum(elem, elem_type))
                    .collect();
                Some(Value::Array { dims, elements })
            }
            (Datum::List(list), ScalarType::List { element_type, .. }) => {
                let elements = list
                    .iter()
                    .map(|elem| Value::from_datum(elem, element_type))
                    .collect();
                Some(Value::List(elements))
            }
            (Datum::List(record), ScalarType::Record { fields, .. }) => {
                let fields = record
                    .iter()
                    .zip(fields)
                    .map(|(e, (_name, ty))| Value::from_datum(e, &ty.scalar_type))
                    .collect();
                Some(Value::Record(fields))
            }
            (Datum::Map(dict), ScalarType::Map { value_type, .. }) => {
                let entries = dict
                    .iter()
                    .map(|(k, v)| (k.to_owned(), Value::from_datum(v, value_type)))
                    .collect();
                Some(Value::Map(entries))
            }
            _ => panic!("can't serialize {}::{:?}", datum, typ),
        }
    }
/// Constructs a new `Value` from a Materialize datum.
///
/// The conversion happens in the obvious manner, except that `Datum::Null`
/// is converted to `None` to align with how PostgreSQL handles NULL.
Constructs a new `Value` from a Materialize datum.
The conversion happens in the obvious manner, except that `Datum::Null`
is converted to `None` to align with how PostgreSQL handles NULL.
Constructs a new ` Value ` from a Materialize datum . The conversion happens in the obvious manner except that ` Datum :: Null ` is converted to ` None ` to align with how PostgreSQL handles NULL .
pub fn from_datum(datum: Datum, typ: &ScalarType) -> Option<Value> {
        match (datum, typ) {
            (Datum::Null, _) => None,
            (Datum::True, ScalarType::Bool) => Some(Value::Bool(true)),
            (Datum::False, ScalarType::Bool) => Some(Value::Bool(false)),
            (Datum::Int16(i), ScalarType::Int16) => Some(Value::Int2(i)),
            (Datum::Int32(i), ScalarType::Int32) => Some(Value::Int4(i)),
            (Datum::Int32(i), ScalarType::Oid) => Some(Value::Int4(i)),
            (Datum::Int32(i), ScalarType::RegClass) => Some(Value::Int4(i)),
            (Datum::Int32(i), ScalarType::RegProc) => Some(Value::Int4(i)),
            (Datum::Int32(i), ScalarType::RegType) => Some(Value::Int4(i)),
            (Datum::Int64(i), ScalarType::Int64) => Some(Value::Int8(i)),
            (Datum::Float32(f), ScalarType::Float32) => Some(Value::Float4(*f)),
            (Datum::Float64(f), ScalarType::Float64) => Some(Value::Float8(*f)),
            (Datum::Numeric(mut d), ScalarType::Numeric { scale }) => {
                if let Some(scale) = scale {
                    adt_numeric::rescale(&mut d.0, *scale).unwrap();
                }
                Some(Value::Numeric(Numeric(d)))
            }
            (Datum::Date(d), ScalarType::Date) => Some(Value::Date(d)),
            (Datum::Time(t), ScalarType::Time) => Some(Value::Time(t)),
            (Datum::Timestamp(ts), ScalarType::Timestamp) => Some(Value::Timestamp(ts)),
            (Datum::TimestampTz(ts), ScalarType::TimestampTz) => Some(Value::TimestampTz(ts)),
            (Datum::Interval(iv), ScalarType::Interval) => Some(Value::Interval(Interval(iv))),
            (Datum::Bytes(b), ScalarType::Bytes) => Some(Value::Bytea(b.to_vec())),
            (Datum::String(s), ScalarType::String) => Some(Value::Text(s.to_owned())),
            (Datum::String(s), ScalarType::VarChar { .. }) => Some(Value::VarChar(s.to_owned())),
            (Datum::String(s), ScalarType::Char { length }) => Some(Value::Char {
                inner: s.to_owned(),
                length: *length,
            }),
            (_, ScalarType::Jsonb) => {
                Some(Value::Jsonb(Jsonb(JsonbRef::from_datum(datum).to_owned())))
            }
            (Datum::Uuid(u), ScalarType::Uuid) => Some(Value::Uuid(u)),
            (Datum::Array(array), ScalarType::Array(elem_type)) => {
                let dims = array.dims().into_iter().collect();
                let elements = array
                    .elements()
                    .iter()
                    .map(|elem| Value::from_datum(elem, elem_type))
                    .collect();
                Some(Value::Array { dims, elements })
            }
            (Datum::List(list), ScalarType::List { element_type, .. }) => {
                let elements = list
                    .iter()
                    .map(|elem| Value::from_datum(elem, element_type))
                    .collect();
                Some(Value::List(elements))
            }
            (Datum::List(record), ScalarType::Record { fields, .. }) => {
                let fields = record
                    .iter()
                    .zip(fields)
                    .map(|(e, (_name, ty))| Value::from_datum(e, &ty.scalar_type))
                    .collect();
                Some(Value::Record(fields))
            }
            (Datum::Map(dict), ScalarType::Map { value_type, .. }) => {
                let entries = dict
                    .iter()
                    .map(|(k, v)| (k.to_owned(), Value::from_datum(v, value_type)))
                    .collect();
                Some(Value::Map(entries))
            }
            _ => panic!("can't serialize {}::{:?}", datum, typ),
        }
    }
pub fn from_datum ( datum : Datum , typ : & ScalarType ) -> Option < Value > { match ( datum , typ ) { ( Datum :: Null , _ ) => None , ( Datum :: True , ScalarType :: Bool ) => Some ( Value :: Bool ( true ) ) , ( Datum :: False , ScalarType :: Bool ) => Some ( Value :: Bool ( false ) ) , ( Datum :: Int16 ( i ) , ScalarType :: Int16 ) => Some ( Value :: Int2 ( i ) ) , ( Datum :: Int32 ( i ) , ScalarType :: Int32 ) => Some ( Value :: Int4 ( i ) ) , ( Datum :: Int32 ( i ) , ScalarType :: Oid ) => Some ( Value :: Int4 ( i ) ) , ( Datum :: Int32 ( i ) , ScalarType :: RegClass ) => Some ( Value :: Int4 ( i ) ) , ( Datum :: Int32 ( i ) , ScalarType :: RegProc ) => Some ( Value :: Int4 ( i ) ) , ( Datum :: Int32 ( i ) , ScalarType :: RegType ) => Some ( Value :: Int4 ( i ) ) , ( Datum :: Int64 ( i ) , ScalarType :: Int64 ) => Some ( Value :: Int8 ( i ) ) , ( Datum :: Float32 ( f ) , ScalarType :: Float32 ) => Some ( Value :: Float4 ( * f ) ) , ( Datum :: Float64 ( f ) , ScalarType :: Float64 ) => Some ( Value :: Float8 ( * f ) ) , ( Datum :: Numeric ( mut d ) , ScalarType :: Numeric { scale } ) => { if let Some ( scale ) = scale { adt_numeric :: rescale ( & mut d . 0 , * scale ) . unwrap ( ) ; } Some ( Value :: Numeric ( Numeric ( d ) ) ) } ( Datum :: Date ( d ) , ScalarType :: Date ) => Some ( Value :: Date ( d ) ) , ( Datum :: Time ( t ) , ScalarType :: Time ) => Some ( Value :: Time ( t ) ) , ( Datum :: Timestamp ( ts ) , ScalarType :: Timestamp ) => Some ( Value :: Timestamp ( ts ) ) , ( Datum :: TimestampTz ( ts ) , ScalarType :: TimestampTz ) => Some ( Value :: TimestampTz ( ts ) ) , ( Datum :: Interval ( iv ) , ScalarType :: Interval ) => Some ( Value :: Interval ( Interval ( iv ) ) ) , ( Datum :: Bytes ( b ) , ScalarType :: Bytes ) => Some ( Value :: Bytea ( b . to_vec ( ) ) ) , ( Datum :: String ( s ) , ScalarType :: String ) => Some ( Value :: Text ( s . to_owned ( ) ) ) , ( Datum :: String ( s ) , ScalarType :: VarChar { .. } ) => Some ( Value :: VarChar ( s . to_owned ( ) ) ) , ( Datum :: String ( s ) , ScalarType :: Char { length } ) => Some ( Value :: Char { inner : s . to_owned ( ) , length : * length , } ) , ( _ , ScalarType :: Jsonb ) => { Some ( Value :: Jsonb ( Jsonb ( JsonbRef :: from_datum ( datum ) . to_owned ( ) ) ) ) } ( Datum :: Uuid ( u ) , ScalarType :: Uuid ) => Some ( Value :: Uuid ( u ) ) , ( Datum :: Array ( array ) , ScalarType :: Array ( elem_type ) ) => { let dims = array . dims ( ) . into_iter ( ) . collect ( ) ; let elements = array . elements ( ) . iter ( ) . map ( | elem | Value :: from_datum ( elem , elem_type ) ) . collect ( ) ; Some ( Value :: Array { dims , elements } ) } ( Datum :: List ( list ) , ScalarType :: List { element_type , .. } ) => { let elements = list . iter ( ) . map ( | elem | Value :: from_datum ( elem , element_type ) ) . collect ( ) ; Some ( Value :: List ( elements ) ) } ( Datum :: List ( record ) , ScalarType :: Record { fields , .. } ) => { let fields = record . iter ( ) . zip ( fields ) . map ( | ( e , ( _name , ty ) ) | Value :: from_datum ( e , & ty . scalar_type ) ) . collect ( ) ; Some ( Value :: Record ( fields ) ) } ( Datum :: Map ( dict ) , ScalarType :: Map { value_type , .. } ) => { let entries = dict . iter ( ) . map ( | ( k , v ) | ( k . to_owned ( ) , Value :: from_datum ( v , value_type ) ) ) . collect ( ) ; Some ( Value :: Map ( entries ) ) } _ => panic ! ( " " datum typ ) , } }
Constructs a new `Value` from a Materialize datum.
Constructs a new ` Value ` from a Materialize datum .
datum
Datum
typ
&ScalarType
datum
Datum
typ
&ScalarType