frame: allow using Timestamp struct as CqlValue
* frame: allow using Timestamp struct as CqlValue
FromCqlVal implementation has been added to frame::value::Time in
but frame::value::Timestamp should have been included too.
@@ -106,6 +106,15 @@ impl FromCqlVal<CqlValue> for crate::frame::value::Time {
}
}
+impl FromCqlVal<CqlValue> for crate::frame::value::Timestamp {
+ fn from_cql(cql_val: CqlValue) -> Result<Self, FromCqlValError> {
+ match cql_val {
+ CqlValue::Timestamp(d) => Ok(Self(d)),
+ _ => Err(FromCqlValError::BadCqlType),
+ }
+ }
+}
+
// Vec<T>::from_cql<CqlValue>
impl<T: FromCqlVal<CqlValue>> FromCqlVal<CqlValue> for Vec<T> {
fn from_cql(cql_val: CqlValue) -> Result<Self, FromCqlValError> {
@@ -422,6 +431,18 @@ mod tests {
);
}
+ #[test]
+ fn timestamp_from_cql() {
+ use crate::frame::value::Timestamp;
+ let timestamp_duration = Duration::milliseconds(86399999999999);
+ assert_eq!(
+ timestamp_duration,
+ Timestamp::from_cql(CqlValue::Timestamp(timestamp_duration))
+ .unwrap()
+ .0,
+ );
+ }
+
#[test]
fn uuid_from_cql() {
let test_uuid: Uuid = Uuid::parse_str("8e14e760-7fa8-11eb-bc66-000000000001").unwrap();
