(x: Datum<'a>)
| 1937 | |
| 1938 | impl<'a> From<Datum<'a>> for ProtoDatum { |
| 1939 | fn from(x: Datum<'a>) -> Self { |
| 1940 | let datum_type = match x { |
| 1941 | Datum::False => DatumType::Other(ProtoDatumOther::False.into()), |
| 1942 | Datum::True => DatumType::Other(ProtoDatumOther::True.into()), |
| 1943 | Datum::Int16(x) => DatumType::Int16(x.into()), |
| 1944 | Datum::Int32(x) => DatumType::Int32(x), |
| 1945 | Datum::UInt8(x) => DatumType::Uint8(x.into()), |
| 1946 | Datum::UInt16(x) => DatumType::Uint16(x.into()), |
| 1947 | Datum::UInt32(x) => DatumType::Uint32(x), |
| 1948 | Datum::UInt64(x) => DatumType::Uint64(x), |
| 1949 | Datum::Int64(x) => DatumType::Int64(x), |
| 1950 | Datum::Float32(x) => DatumType::Float32(x.into_inner()), |
| 1951 | Datum::Float64(x) => DatumType::Float64(x.into_inner()), |
| 1952 | Datum::Date(x) => DatumType::Date(x.into_proto()), |
| 1953 | Datum::Time(x) => DatumType::Time(ProtoNaiveTime { |
| 1954 | secs: x.num_seconds_from_midnight(), |
| 1955 | frac: x.nanosecond(), |
| 1956 | }), |
| 1957 | Datum::Timestamp(x) => DatumType::Timestamp(x.into_proto()), |
| 1958 | Datum::TimestampTz(x) => DatumType::TimestampTz(x.into_proto()), |
| 1959 | Datum::Interval(x) => DatumType::Interval(x.into_proto()), |
| 1960 | Datum::Bytes(x) => DatumType::Bytes(Bytes::copy_from_slice(x)), |
| 1961 | Datum::String(x) => DatumType::String(x.to_owned()), |
| 1962 | Datum::Array(x) => DatumType::Array(ProtoArray { |
| 1963 | elements: Some(ProtoRow { |
| 1964 | datums: x.elements().iter().map(|x| x.into()).collect(), |
| 1965 | }), |
| 1966 | dims: x |
| 1967 | .dims() |
| 1968 | .into_iter() |
| 1969 | .map(|x| ProtoArrayDimension { |
| 1970 | lower_bound: i64::cast_from(x.lower_bound), |
| 1971 | length: u64::cast_from(x.length), |
| 1972 | }) |
| 1973 | .collect(), |
| 1974 | }), |
| 1975 | Datum::List(x) => DatumType::List(ProtoRow { |
| 1976 | datums: x.iter().map(|x| x.into()).collect(), |
| 1977 | }), |
| 1978 | Datum::Map(x) => DatumType::Dict(ProtoDict { |
| 1979 | elements: x |
| 1980 | .iter() |
| 1981 | .map(|(k, v)| ProtoDictElement { |
| 1982 | key: k.to_owned(), |
| 1983 | val: Some(v.into()), |
| 1984 | }) |
| 1985 | .collect(), |
| 1986 | }), |
| 1987 | Datum::Numeric(x) => { |
| 1988 | // TODO: Do we need this defensive clone? |
| 1989 | let mut x = x.0.clone(); |
| 1990 | if let Some((bcd, scale)) = x.to_packed_bcd() { |
| 1991 | DatumType::Numeric(ProtoNumeric { bcd, scale }) |
| 1992 | } else if x.is_nan() { |
| 1993 | DatumType::Other(ProtoDatumOther::NumericNaN.into()) |
| 1994 | } else if x.is_infinite() { |
| 1995 | if x.is_negative() { |
| 1996 | DatumType::Other(ProtoDatumOther::NumericNegInf.into()) |
nothing calls this directly
no test coverage detected