From 751a6c7e61eeefd388c2711007215bc2dfba89b5 Mon Sep 17 00:00:00 2001 From: muzarski Date: Thu, 22 Feb 2024 16:29:20 +0100 Subject: [PATCH] cargo: rename `time` feature to `time-03`. --- .github/workflows/rust.yml | 2 +- examples/Cargo.toml | 2 +- scylla-cql/Cargo.toml | 8 +- scylla-cql/src/frame/response/cql_to_rust.rs | 95 +++++++++++--------- scylla-cql/src/frame/response/result.rs | 32 +++---- scylla-cql/src/frame/value.rs | 72 +++++++-------- scylla-cql/src/frame/value_tests.rs | 35 ++++---- scylla-cql/src/types/serialize/value.rs | 12 +-- scylla/Cargo.toml | 4 +- scylla/src/transport/cql_types_test.rs | 6 +- 10 files changed, 141 insertions(+), 127 deletions(-) diff --git a/.github/workflows/rust.yml b/.github/workflows/rust.yml index 79a68122d0..96c151da11 100644 --- a/.github/workflows/rust.yml +++ b/.github/workflows/rust.yml @@ -39,7 +39,7 @@ jobs: - name: Cargo check with chrono feature run: cargo check --all-targets --manifest-path "scylla/Cargo.toml" --features "chrono" - name: Cargo check with time feature - run: cargo check --all-targets --manifest-path "scylla/Cargo.toml" --features "time" + run: cargo check --all-targets --manifest-path "scylla/Cargo.toml" --features "time-03" - name: Cargo check with num-bigint-03 feature run: cargo check --all-targets --manifest-path "scylla/Cargo.toml" --features "num-bigint-03" - name: Cargo check with num-bigint-04 feature diff --git a/examples/Cargo.toml b/examples/Cargo.toml index b068ee9e3c..fa31107e8c 100644 --- a/examples/Cargo.toml +++ b/examples/Cargo.toml @@ -10,7 +10,7 @@ futures = "0.3.6" openssl = "0.10.32" rustyline = "9" rustyline-derive = "0.6" -scylla = {path = "../scylla", features = ["ssl", "cloud", "chrono", "time", "num-bigint-03", "num-bigint-04", "bigdecimal-04"]} +scylla = {path = "../scylla", features = ["ssl", "cloud", "chrono", "time-03", "num-bigint-03", "num-bigint-04", "bigdecimal-04"]} tokio = {version = "1.1.0", features = ["full"]} tracing = "0.1.25" tracing-subscriber = { version = "0.3.14", features = ["env-filter"] } diff --git a/scylla-cql/Cargo.toml b/scylla-cql/Cargo.toml index 7363b0ad8d..9ccc8b5189 100644 --- a/scylla-cql/Cargo.toml +++ b/scylla-cql/Cargo.toml @@ -25,12 +25,12 @@ chrono = { version = "0.4.32", default-features = false, optional = true } lz4_flex = { version = "0.11.1" } async-trait = "0.1.57" serde = { version = "1.0", features = ["derive"], optional = true } -time = { version = "0.3", optional = true } +time-03 = { package = "time", version = "0.3", optional = true } [dev-dependencies] criterion = "0.4" # Note: v0.5 needs at least rust 1.70.0 # Use large-dates feature to test potential edge cases -time = { version = "0.3.21", features = ["large-dates"] } +time-03 = { package = "time", version = "0.3.21", features = ["large-dates"] } [[bench]] name = "benchmark" @@ -38,12 +38,12 @@ harness = false [features] secrecy-08 = ["dep:secrecy-08"] -time = ["dep:time"] +time-03 = ["dep:time-03"] chrono = ["dep:chrono"] num-bigint-03 = ["dep:num-bigint-03"] num-bigint-04 = ["dep:num-bigint-04"] bigdecimal-04 = ["dep:bigdecimal-04"] -full-serialization = ["chrono", "time", "secrecy-08", "num-bigint-03", "num-bigint-04", "bigdecimal-04"] +full-serialization = ["chrono", "time-03", "secrecy-08", "num-bigint-03", "num-bigint-04", "bigdecimal-04"] [lints.rust] unreachable_pub = "warn" diff --git a/scylla-cql/src/frame/response/cql_to_rust.rs b/scylla-cql/src/frame/response/cql_to_rust.rs index a56a726fc5..525eb4d1ee 100644 --- a/scylla-cql/src/frame/response/cql_to_rust.rs +++ b/scylla-cql/src/frame/response/cql_to_rust.rs @@ -188,8 +188,8 @@ impl FromCqlVal for NaiveDate { } } -#[cfg(feature = "time")] -impl FromCqlVal for time::Date { +#[cfg(feature = "time-03")] +impl FromCqlVal for time_03::Date { fn from_cql(cql_val: CqlValue) -> Result { match cql_val { CqlValue::Date(cql_date) => cql_date.try_into().map_err(|_| FromCqlValError::BadVal), @@ -208,8 +208,8 @@ impl FromCqlVal for NaiveTime { } } -#[cfg(feature = "time")] -impl FromCqlVal for time::Time { +#[cfg(feature = "time-03")] +impl FromCqlVal for time_03::Time { fn from_cql(cql_val: CqlValue) -> Result { match cql_val { CqlValue::Time(cql_time) => cql_time.try_into().map_err(|_| FromCqlValError::BadVal), @@ -229,8 +229,8 @@ impl FromCqlVal for DateTime { } } -#[cfg(feature = "time")] -impl FromCqlVal for time::OffsetDateTime { +#[cfg(feature = "time-03")] +impl FromCqlVal for time_03::OffsetDateTime { fn from_cql(cql_val: CqlValue) -> Result { cql_val .as_cql_timestamp() @@ -568,43 +568,49 @@ mod tests { assert_eq!(Ok(CqlDate(u32::MAX)), CqlDate::from_cql(max_date)); } - #[cfg(feature = "time")] + #[cfg(feature = "time-03")] #[test] fn date_from_cql() { // UNIX epoch let unix_epoch = CqlValue::Date(CqlDate(1 << 31)); assert_eq!( - Ok(time::Date::from_ordinal_date(1970, 1).unwrap()), - time::Date::from_cql(unix_epoch) + Ok(time_03::Date::from_ordinal_date(1970, 1).unwrap()), + time_03::Date::from_cql(unix_epoch) ); // 7 days after UNIX epoch let after_epoch = CqlValue::Date(CqlDate((1 << 31) + 7)); assert_eq!( - Ok(time::Date::from_ordinal_date(1970, 8).unwrap()), - time::Date::from_cql(after_epoch) + Ok(time_03::Date::from_ordinal_date(1970, 8).unwrap()), + time_03::Date::from_cql(after_epoch) ); // 3 days before UNIX epoch let before_epoch = CqlValue::Date(CqlDate((1 << 31) - 3)); assert_eq!( - Ok(time::Date::from_ordinal_date(1969, 363).unwrap()), - time::Date::from_cql(before_epoch) + Ok(time_03::Date::from_ordinal_date(1969, 363).unwrap()), + time_03::Date::from_cql(before_epoch) ); - // Min possible stored date. Since value is out of `time::Date` range, it should return `BadVal` error + // Min possible stored date. Since value is out of `time_03::Date` range, it should return `BadVal` error let min_date = CqlValue::Date(CqlDate(u32::MIN)); - assert_eq!(Err(FromCqlValError::BadVal), time::Date::from_cql(min_date)); + assert_eq!( + Err(FromCqlValError::BadVal), + time_03::Date::from_cql(min_date) + ); - // Max possible stored date. Since value is out of `time::Date` range, it should return `BadVal` error + // Max possible stored date. Since value is out of `time_03::Date` range, it should return `BadVal` error let max_date = CqlValue::Date(CqlDate(u32::MAX)); - assert_eq!(Err(FromCqlValError::BadVal), time::Date::from_cql(max_date)); + assert_eq!( + Err(FromCqlValError::BadVal), + time_03::Date::from_cql(max_date) + ); // Different CQL type. Since value can't be casted, it should return `BadCqlType` error let bad_type = CqlValue::Double(0.5); assert_eq!( Err(FromCqlValError::BadCqlType), - time::Date::from_cql(bad_type) + time_03::Date::from_cql(bad_type) ); } @@ -669,20 +675,23 @@ mod tests { ); } - #[cfg(feature = "time")] + #[cfg(feature = "time-03")] #[test] fn time_from_cql() { // Midnight let midnight = CqlValue::Time(CqlTime(0)); - assert_eq!(Ok(time::Time::MIDNIGHT), time::Time::from_cql(midnight)); + assert_eq!( + Ok(time_03::Time::MIDNIGHT), + time_03::Time::from_cql(midnight) + ); // 7:15:21.123456789 let morning = CqlValue::Time(CqlTime( (7 * 3600 + 15 * 60 + 21) * 1_000_000_000 + 123_456_789, )); assert_eq!( - Ok(time::Time::from_hms_nano(7, 15, 21, 123_456_789).unwrap()), - time::Time::from_cql(morning) + Ok(time_03::Time::from_hms_nano(7, 15, 21, 123_456_789).unwrap()), + time_03::Time::from_cql(morning) ); // 23:59:59.999999999 @@ -690,27 +699,27 @@ mod tests { (23 * 3600 + 59 * 60 + 59) * 1_000_000_000 + 999_999_999, )); assert_eq!( - Ok(time::Time::from_hms_nano(23, 59, 59, 999_999_999).unwrap()), - time::Time::from_cql(late_night) + Ok(time_03::Time::from_hms_nano(23, 59, 59, 999_999_999).unwrap()), + time_03::Time::from_cql(late_night) ); - // Bad values. Since value is out of `time::Time` range, it should return `BadVal` error + // Bad values. Since value is out of `time_03::Time` range, it should return `BadVal` error let bad_time1 = CqlValue::Time(CqlTime(-1)); assert_eq!( Err(FromCqlValError::BadVal), - time::Time::from_cql(bad_time1) + time_03::Time::from_cql(bad_time1) ); let bad_time2 = CqlValue::Time(CqlTime(i64::MAX)); assert_eq!( Err(FromCqlValError::BadVal), - time::Time::from_cql(bad_time2) + time_03::Time::from_cql(bad_time2) ); // Different CQL type. Since value can't be casted, it should return `BadCqlType` error let bad_type = CqlValue::Double(0.5); assert_eq!( Err(FromCqlValError::BadCqlType), - time::Time::from_cql(bad_type) + time_03::Time::from_cql(bad_type) ); } @@ -744,55 +753,55 @@ mod tests { ); } - #[cfg(feature = "time")] + #[cfg(feature = "time-03")] #[test] fn offset_datetime_from_cql() { // UNIX epoch let unix_epoch = CqlValue::Timestamp(CqlTimestamp(0)); assert_eq!( - Ok(time::OffsetDateTime::UNIX_EPOCH), - time::OffsetDateTime::from_cql(unix_epoch) + Ok(time_03::OffsetDateTime::UNIX_EPOCH), + time_03::OffsetDateTime::from_cql(unix_epoch) ); // 1 day 2 hours 3 minutes 4 seconds and 5 nanoseconds before UNIX epoch let before_epoch = CqlValue::Timestamp(CqlTimestamp(-(26 * 3600 + 3 * 60 + 4) * 1000 - 5)); assert_eq!( - Ok(time::OffsetDateTime::UNIX_EPOCH - - time::Duration::new(26 * 3600 + 3 * 60 + 4, 5 * 1_000_000)), - time::OffsetDateTime::from_cql(before_epoch) + Ok(time_03::OffsetDateTime::UNIX_EPOCH + - time_03::Duration::new(26 * 3600 + 3 * 60 + 4, 5 * 1_000_000)), + time_03::OffsetDateTime::from_cql(before_epoch) ); // 6 days 7 hours 8 minutes 9 seconds and 10 nanoseconds after UNIX epoch let after_epoch = CqlValue::Timestamp(CqlTimestamp(((6 * 24 + 7) * 3600 + 8 * 60 + 9) * 1000 + 10)); assert_eq!( - Ok(time::PrimitiveDateTime::new( - time::Date::from_ordinal_date(1970, 7).unwrap(), - time::Time::from_hms_milli(7, 8, 9, 10).unwrap() + Ok(time_03::PrimitiveDateTime::new( + time_03::Date::from_ordinal_date(1970, 7).unwrap(), + time_03::Time::from_hms_milli(7, 8, 9, 10).unwrap() ) .assume_utc()), - time::OffsetDateTime::from_cql(after_epoch) + time_03::OffsetDateTime::from_cql(after_epoch) ); - // Min possible stored timestamp. Since value is out of `time::OffsetDateTime` range, it should return `BadVal` error + // Min possible stored timestamp. Since value is out of `time_03::OffsetDateTime` range, it should return `BadVal` error let min_timestamp = CqlValue::Timestamp(CqlTimestamp(i64::MIN)); assert_eq!( Err(FromCqlValError::BadVal), - time::OffsetDateTime::from_cql(min_timestamp) + time_03::OffsetDateTime::from_cql(min_timestamp) ); - // Max possible stored timestamp. Since value is out of `time::OffsetDateTime` range, it should return `BadVal` error + // Max possible stored timestamp. Since value is out of `time_03::OffsetDateTime` range, it should return `BadVal` error let max_timestamp = CqlValue::Timestamp(CqlTimestamp(i64::MAX)); assert_eq!( Err(FromCqlValError::BadVal), - time::OffsetDateTime::from_cql(max_timestamp) + time_03::OffsetDateTime::from_cql(max_timestamp) ); // Different CQL type. Since value can't be casted, it should return `BadCqlType` error let bad_type = CqlValue::Double(0.5); assert_eq!( Err(FromCqlValError::BadCqlType), - time::OffsetDateTime::from_cql(bad_type) + time_03::OffsetDateTime::from_cql(bad_type) ); } diff --git a/scylla-cql/src/frame/response/result.rs b/scylla-cql/src/frame/response/result.rs index 75c7a15058..23a39ee198 100644 --- a/scylla-cql/src/frame/response/result.rs +++ b/scylla-cql/src/frame/response/result.rs @@ -161,8 +161,8 @@ impl CqlValue { self.as_cql_date().and_then(|date| date.try_into().ok()) } - #[cfg(feature = "time")] - pub fn as_date(&self) -> Option { + #[cfg(feature = "time-03")] + pub fn as_date(&self) -> Option { self.as_cql_date().and_then(|date| date.try_into().ok()) } @@ -178,8 +178,8 @@ impl CqlValue { self.as_cql_timestamp().and_then(|ts| ts.try_into().ok()) } - #[cfg(feature = "time")] - pub fn as_offset_date_time(&self) -> Option { + #[cfg(feature = "time-03")] + pub fn as_offset_date_time(&self) -> Option { self.as_cql_timestamp().and_then(|ts| ts.try_into().ok()) } @@ -195,8 +195,8 @@ impl CqlValue { self.as_cql_time().and_then(|ts| ts.try_into().ok()) } - #[cfg(feature = "time")] - pub fn as_time(&self) -> Option { + #[cfg(feature = "time-03")] + pub fn as_time(&self) -> Option { self.as_cql_time().and_then(|ts| ts.try_into().ok()) } @@ -1411,13 +1411,13 @@ mod tests { ); } - #[cfg(feature = "time")] + #[cfg(feature = "time-03")] #[test] fn test_date_from_cql() { - use time::Date; - use time::Month::*; + use time_03::Date; + use time_03::Month::*; - // 2^31 when converted to time::Date is 1970-01-01 + // 2^31 when converted to time_03::Date is 1970-01-01 let unix_epoch = Date::from_calendar_date(1970, January, 1).unwrap(); let date = super::deser_cql_value(&ColumnType::Date, &mut (1u32 << 31).to_be_bytes().as_ref()) @@ -1425,7 +1425,7 @@ mod tests { assert_eq!(date.as_date(), Some(unix_epoch)); - // 2^31 - 30 when converted to time::Date is 1969-12-02 + // 2^31 - 30 when converted to time_03::Date is 1969-12-02 let before_epoch = Date::from_calendar_date(1969, December, 2).unwrap(); let date = super::deser_cql_value( &ColumnType::Date, @@ -1435,7 +1435,7 @@ mod tests { assert_eq!(date.as_date(), Some(before_epoch)); - // 2^31 + 30 when converted to time::Date is 1970-01-31 + // 2^31 + 30 when converted to time_03::Date is 1970-01-31 let after_epoch = Date::from_calendar_date(1970, January, 31).unwrap(); let date = super::deser_cql_value( &ColumnType::Date, @@ -1524,10 +1524,10 @@ mod tests { assert_eq!(time.as_naive_time(), Some(midnight)); } - #[cfg(feature = "time")] + #[cfg(feature = "time-03")] #[test] fn test_primitive_time_from_cql() { - use time::Time; + use time_03::Time; // 0 when converted to NaiveTime is 0:0:0.0 let midnight = Time::from_hms_nano(0, 0, 0, 0).unwrap(); @@ -1635,10 +1635,10 @@ mod tests { ); } - #[cfg(feature = "time")] + #[cfg(feature = "time-03")] #[test] fn test_offset_datetime_from_cql() { - use time::{Date, Month::*, OffsetDateTime, PrimitiveDateTime, Time}; + use time_03::{Date, Month::*, OffsetDateTime, PrimitiveDateTime, Time}; // 0 when converted to OffsetDateTime is 1970-01-01 0:00:00.00 let unix_epoch = OffsetDateTime::from_unix_timestamp(0).unwrap(); diff --git a/scylla-cql/src/frame/value.rs b/scylla-cql/src/frame/value.rs index 3d13d5ef52..d50b7eb05c 100644 --- a/scylla-cql/src/frame/value.rs +++ b/scylla-cql/src/frame/value.rs @@ -551,17 +551,19 @@ impl TryInto for CqlTime { } } -#[cfg(feature = "time")] -impl From for CqlDate { - fn from(value: time::Date) -> Self { +#[cfg(feature = "time-03")] +impl From for CqlDate { + fn from(value: time_03::Date) -> Self { const JULIAN_DAY_OFFSET: i64 = - (1 << 31) - time::OffsetDateTime::UNIX_EPOCH.date().to_julian_day() as i64; + (1 << 31) - time_03::OffsetDateTime::UNIX_EPOCH.date().to_julian_day() as i64; // Statically assert that no possible value will ever overflow - const _: () = - assert!(time::Date::MAX.to_julian_day() as i64 + JULIAN_DAY_OFFSET < u32::MAX as i64); - const _: () = - assert!(time::Date::MIN.to_julian_day() as i64 + JULIAN_DAY_OFFSET > u32::MIN as i64); + const _: () = assert!( + time_03::Date::MAX.to_julian_day() as i64 + JULIAN_DAY_OFFSET < u32::MAX as i64 + ); + const _: () = assert!( + time_03::Date::MIN.to_julian_day() as i64 + JULIAN_DAY_OFFSET > u32::MIN as i64 + ); let days = value.to_julian_day() as i64 + JULIAN_DAY_OFFSET; @@ -569,29 +571,29 @@ impl From for CqlDate { } } -#[cfg(feature = "time")] -impl TryInto for CqlDate { +#[cfg(feature = "time-03")] +impl TryInto for CqlDate { type Error = ValueOverflow; - fn try_into(self) -> Result { + fn try_into(self) -> Result { const JULIAN_DAY_OFFSET: i64 = - (1 << 31) - time::OffsetDateTime::UNIX_EPOCH.date().to_julian_day() as i64; + (1 << 31) - time_03::OffsetDateTime::UNIX_EPOCH.date().to_julian_day() as i64; let julian_days = (self.0 as i64 - JULIAN_DAY_OFFSET) .try_into() .map_err(|_| ValueOverflow)?; - time::Date::from_julian_day(julian_days).map_err(|_| ValueOverflow) + time_03::Date::from_julian_day(julian_days).map_err(|_| ValueOverflow) } } -#[cfg(feature = "time")] -impl From for CqlTimestamp { - fn from(value: time::OffsetDateTime) -> Self { +#[cfg(feature = "time-03")] +impl From for CqlTimestamp { + fn from(value: time_03::OffsetDateTime) -> Self { // Statically assert that no possible value will ever overflow. OffsetDateTime doesn't allow offset to overflow // the UTC PrimitiveDateTime value value const _: () = assert!( - time::PrimitiveDateTime::MAX + time_03::PrimitiveDateTime::MAX .assume_utc() .unix_timestamp_nanos() // Nanos to millis @@ -599,7 +601,7 @@ impl From for CqlTimestamp { < i64::MAX as i128 ); const _: () = assert!( - time::PrimitiveDateTime::MIN + time_03::PrimitiveDateTime::MIN .assume_utc() .unix_timestamp_nanos() / 1_000_000 @@ -611,19 +613,19 @@ impl From for CqlTimestamp { } } -#[cfg(feature = "time")] -impl TryInto for CqlTimestamp { +#[cfg(feature = "time-03")] +impl TryInto for CqlTimestamp { type Error = ValueOverflow; - fn try_into(self) -> Result { - time::OffsetDateTime::from_unix_timestamp_nanos(self.0 as i128 * 1_000_000) + fn try_into(self) -> Result { + time_03::OffsetDateTime::from_unix_timestamp_nanos(self.0 as i128 * 1_000_000) .map_err(|_| ValueOverflow) } } -#[cfg(feature = "time")] -impl From for CqlTime { - fn from(value: time::Time) -> Self { +#[cfg(feature = "time-03")] +impl From for CqlTime { + fn from(value: time_03::Time) -> Self { let (h, m, s, n) = value.as_hms_nano(); // no need for checked arithmetic as all these types are guaranteed to fit in i64 without overflow @@ -633,17 +635,17 @@ impl From for CqlTime { } } -#[cfg(feature = "time")] -impl TryInto for CqlTime { +#[cfg(feature = "time-03")] +impl TryInto for CqlTime { type Error = ValueOverflow; - fn try_into(self) -> Result { + fn try_into(self) -> Result { let h = self.0 / 3_600_000_000_000; let m = self.0 / 60_000_000_000 % 60; let s = self.0 / 1_000_000_000 % 60; let n = self.0 % 1_000_000_000; - time::Time::from_hms_nano( + time_03::Time::from_hms_nano( h.try_into().map_err(|_| ValueOverflow)?, m as u8, s as u8, @@ -1017,8 +1019,8 @@ impl Value for CqlDate { } } -#[cfg(feature = "time")] -impl Value for time::Date { +#[cfg(feature = "time-03")] +impl Value for time_03::Date { fn serialize(&self, buf: &mut Vec) -> Result<(), ValueTooBig> { CqlDate::from(*self).serialize(buf) } @@ -1047,8 +1049,8 @@ impl Value for DateTime { } } -#[cfg(feature = "time")] -impl Value for time::OffsetDateTime { +#[cfg(feature = "time-03")] +impl Value for time_03::OffsetDateTime { fn serialize(&self, buf: &mut Vec) -> Result<(), ValueTooBig> { CqlTimestamp::from(*self).serialize(buf) } @@ -1063,8 +1065,8 @@ impl Value for NaiveTime { } } -#[cfg(feature = "time")] -impl Value for time::Time { +#[cfg(feature = "time-03")] +impl Value for time_03::Time { fn serialize(&self, buf: &mut Vec) -> Result<(), ValueTooBig> { CqlTime::from(*self).serialize(buf) } diff --git a/scylla-cql/src/frame/value_tests.rs b/scylla-cql/src/frame/value_tests.rs index 3868928f98..c0201b2f56 100644 --- a/scylla-cql/src/frame/value_tests.rs +++ b/scylla-cql/src/frame/value_tests.rs @@ -333,11 +333,11 @@ fn naive_date_serialization() { assert_eq!((2_u32.pow(31) + 30).to_be_bytes(), [128, 0, 0, 30]); } -#[cfg(feature = "time")] +#[cfg(feature = "time-03")] #[test] fn date_serialization() { // 1970-01-31 is 2^31 - let unix_epoch = time::Date::from_ordinal_date(1970, 1).unwrap(); + let unix_epoch = time_03::Date::from_ordinal_date(1970, 1).unwrap(); assert_eq!( serialized(unix_epoch, ColumnType::Date), vec![0, 0, 0, 4, 128, 0, 0, 0] @@ -345,7 +345,8 @@ fn date_serialization() { assert_eq!(2_u32.pow(31).to_be_bytes(), [128, 0, 0, 0]); // 1969-12-02 is 2^31 - 30 - let before_epoch = time::Date::from_calendar_date(1969, time::Month::December, 2).unwrap(); + let before_epoch = + time_03::Date::from_calendar_date(1969, time_03::Month::December, 2).unwrap(); assert_eq!( serialized(before_epoch, ColumnType::Date), vec![0, 0, 0, 4, 127, 255, 255, 226] @@ -353,15 +354,16 @@ fn date_serialization() { assert_eq!((2_u32.pow(31) - 30).to_be_bytes(), [127, 255, 255, 226]); // 1970-01-31 is 2^31 + 30 - let after_epoch = time::Date::from_calendar_date(1970, time::Month::January, 31).unwrap(); + let after_epoch = time_03::Date::from_calendar_date(1970, time_03::Month::January, 31).unwrap(); assert_eq!( serialized(after_epoch, ColumnType::Date), vec![0, 0, 0, 4, 128, 0, 0, 30] ); assert_eq!((2_u32.pow(31) + 30).to_be_bytes(), [128, 0, 0, 30]); - // Min date represented by time::Date (without large-dates feature) - let long_before_epoch = time::Date::from_calendar_date(-9999, time::Month::January, 1).unwrap(); + // Min date represented by time_03::Date (without large-dates feature) + let long_before_epoch = + time_03::Date::from_calendar_date(-9999, time_03::Month::January, 1).unwrap(); let days_till_epoch = (unix_epoch - long_before_epoch).whole_days(); assert_eq!( (2_u32.pow(31) - days_till_epoch as u32).to_be_bytes(), @@ -372,8 +374,9 @@ fn date_serialization() { vec![0, 0, 0, 4, 127, 189, 75, 125] ); - // Max date represented by time::Date (without large-dates feature) - let long_after_epoch = time::Date::from_calendar_date(9999, time::Month::December, 31).unwrap(); + // Max date represented by time_03::Date (without large-dates feature) + let long_after_epoch = + time_03::Date::from_calendar_date(9999, time_03::Month::December, 31).unwrap(); let days_since_epoch = (long_after_epoch - unix_epoch).whole_days(); assert_eq!( (2_u32.pow(31) + days_since_epoch as u32).to_be_bytes(), @@ -444,20 +447,20 @@ fn naive_time_serialization() { ) } -#[cfg(feature = "time")] +#[cfg(feature = "time-03")] #[test] fn time_serialization() { let midnight_time: i64 = 0; let max_time: i64 = 24 * 60 * 60 * 1_000_000_000 - 1; let any_time: i64 = (3600 + 2 * 60 + 3) * 1_000_000_000 + 4; let test_cases = [ - (time::Time::MIDNIGHT, midnight_time.to_be_bytes()), + (time_03::Time::MIDNIGHT, midnight_time.to_be_bytes()), ( - time::Time::from_hms_nano(23, 59, 59, 999_999_999).unwrap(), + time_03::Time::from_hms_nano(23, 59, 59, 999_999_999).unwrap(), max_time.to_be_bytes(), ), ( - time::Time::from_hms_nano(1, 2, 3, 4).unwrap(), + time_03::Time::from_hms_nano(1, 2, 3, 4).unwrap(), any_time.to_be_bytes(), ), ]; @@ -539,14 +542,14 @@ fn date_time_serialization() { } } -#[cfg(feature = "time")] +#[cfg(feature = "time-03")] #[test] fn offset_date_time_serialization() { - use time::{Date, Month, OffsetDateTime, PrimitiveDateTime, Time}; + use time_03::{Date, Month, OffsetDateTime, PrimitiveDateTime, Time}; let offset_max = - PrimitiveDateTime::MAX.assume_offset(time::UtcOffset::from_hms(-23, -59, -59).unwrap()); + PrimitiveDateTime::MAX.assume_offset(time_03::UtcOffset::from_hms(-23, -59, -59).unwrap()); let offset_min = - PrimitiveDateTime::MIN.assume_offset(time::UtcOffset::from_hms(23, 59, 59).unwrap()); + PrimitiveDateTime::MIN.assume_offset(time_03::UtcOffset::from_hms(23, 59, 59).unwrap()); let test_cases = [ ( // Max time serialized without error diff --git a/scylla-cql/src/types/serialize/value.rs b/scylla-cql/src/types/serialize/value.rs index 6583f7b002..50481ba30a 100644 --- a/scylla-cql/src/types/serialize/value.rs +++ b/scylla-cql/src/types/serialize/value.rs @@ -184,22 +184,22 @@ impl SerializeCql for NaiveTime { ::serialize(&cql_time, typ, writer)? }); } -#[cfg(feature = "time")] -impl SerializeCql for time::Date { +#[cfg(feature = "time-03")] +impl SerializeCql for time_03::Date { impl_serialize_via_writer!(|me, typ, writer| { exact_type_check!(typ, Date); ::serialize(&(*me).into(), typ, writer)? }); } -#[cfg(feature = "time")] -impl SerializeCql for time::OffsetDateTime { +#[cfg(feature = "time-03")] +impl SerializeCql for time_03::OffsetDateTime { impl_serialize_via_writer!(|me, typ, writer| { exact_type_check!(typ, Timestamp); ::serialize(&(*me).into(), typ, writer)? }); } -#[cfg(feature = "time")] -impl SerializeCql for time::Time { +#[cfg(feature = "time-03")] +impl SerializeCql for time_03::Time { impl_serialize_via_writer!(|me, typ, writer| { exact_type_check!(typ, Time); ::serialize(&(*me).into(), typ, writer)? diff --git a/scylla/Cargo.toml b/scylla/Cargo.toml index 447ec8bf56..85f606f407 100644 --- a/scylla/Cargo.toml +++ b/scylla/Cargo.toml @@ -19,11 +19,11 @@ ssl = ["dep:tokio-openssl", "dep:openssl"] cloud = ["ssl", "scylla-cql/serde", "dep:serde_yaml", "dep:serde", "dep:url", "dep:base64"] secrecy-08 = ["scylla-cql/secrecy-08"] chrono = ["scylla-cql/chrono"] -time = ["scylla-cql/time"] +time-03 = ["scylla-cql/time-03"] num-bigint-03 = ["scylla-cql/num-bigint-03"] num-bigint-04 = ["scylla-cql/num-bigint-04"] bigdecimal-04 = ["scylla-cql/bigdecimal-04"] -full-serialization = ["chrono", "time", "secrecy-08", "num-bigint-03", "num-bigint-04", "bigdecimal-04"] +full-serialization = ["chrono", "time-03", "secrecy-08", "num-bigint-03", "num-bigint-04", "bigdecimal-04"] [dependencies] scylla-macros = { version = "0.4.0", path = "../scylla-macros" } diff --git a/scylla/src/transport/cql_types_test.rs b/scylla/src/transport/cql_types_test.rs index 8429a6ce0e..459de7fcfe 100644 --- a/scylla/src/transport/cql_types_test.rs +++ b/scylla/src/transport/cql_types_test.rs @@ -448,7 +448,7 @@ async fn test_cql_date() { .unwrap_err(); } -#[cfg(feature = "time")] +#[cfg(feature = "time-03")] #[tokio::test] async fn test_date() { setup_tracing(); @@ -700,7 +700,7 @@ async fn test_naive_time() { .unwrap_err(); } -#[cfg(feature = "time")] +#[cfg(feature = "time-03")] #[tokio::test] async fn test_time() { setup_tracing(); @@ -1003,7 +1003,7 @@ async fn test_date_time() { .unwrap_err(); } -#[cfg(feature = "time")] +#[cfg(feature = "time-03")] #[tokio::test] async fn test_offset_date_time() { setup_tracing();