Skip to content

Commit

Permalink
Updated Prost to 0.12.3 and set MSRV to 1.70
Browse files Browse the repository at this point in the history
  • Loading branch information
fdeantoni committed Mar 13, 2024
1 parent 7208aab commit bedabbb
Show file tree
Hide file tree
Showing 7 changed files with 31 additions and 24 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/rust.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ jobs:
- windows-latest
rust:
- stable
- 1.65.0
- 1.70.0

steps:
- uses: actions/checkout@v2
Expand Down
4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,13 @@ description = "Helper crate for prost to allow JSON serialization and deserializ
readme = "README.md"
documentation = "https://docs.rs/prost-wkt-derive"
edition = "2021"
rust-version = "1.60"
rust-version = "1.70"

[workspace]
members = [ "wkt-build", "wkt-types", "example" ]

[dependencies]
prost = "0.12.1"
prost = "0.12.3"
inventory = "0.3.0"
serde = "1.0"
serde_json = "1.0"
Expand Down
6 changes: 3 additions & 3 deletions example/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@ name = "prost-wkt-example"
version = "0.5.1"
authors = ["fdeantoni <fdeantoni@gmail.com>"]
edition = "2021"
rust-version = "1.60"
rust-version = "1.70"

[dependencies]
prost = "0.12.1"
prost = "0.12.3"
prost-wkt = { path = ".." }
prost-wkt-types = { path = "../wkt-types" }
serde = "1.0"
Expand All @@ -15,5 +15,5 @@ serde_json = "1.0"
chrono = { version = "0.4", default-features = false, features = ["clock", "serde"] }

[build-dependencies]
prost-build = "0.12.1"
prost-build = "0.12.3"
prost-wkt-build = { path = "../wkt-build" }
8 changes: 4 additions & 4 deletions wkt-build/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@ description = "Helper crate for prost to allow JSON serialization and deserializ
readme = "../README.md"
documentation = "https://docs.rs/prost-wkt-build"
edition = "2021"
rust-version = "1.60"
rust-version = "1.70"

[dependencies]
prost = "0.12.1"
prost-types = "0.12.1"
prost-build = "0.12.1"
prost = "0.12.3"
prost-types = "0.12.3"
prost-build = "0.12.3"
quote = "1.0"
heck = "0.4"
12 changes: 6 additions & 6 deletions wkt-types/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ documentation = "https://docs.rs/prost-wkt"
keywords = ["protobuf", "serde", "json"]
categories = ["encoding"]
edition = "2021"
rust-version = "1.60"
rust-version = "1.70"

[lib]
doctest = false
Expand All @@ -23,17 +23,17 @@ vendored-protox = ["protox"]

[dependencies]
prost-wkt = { version = "0.5.1", path = ".." }
prost = "0.12.1"
prost = "0.12.3"
serde = "1.0"
serde_json = "1.0"
serde_derive = "1.0"
chrono = { version = "0.4.27", default-features = false, features = ["serde"] }

[build-dependencies]
prost = "0.12.1"
prost-types = "0.12.1"
prost-build = "0.12.1"
prost = "0.12.3"
prost-types = "0.12.3"
prost-build = "0.12.3"
prost-wkt-build = { version = "0.5.1", path = "../wkt-build" }
regex = "1"
protobuf-src = { version = "1.1.0", optional = true }
protox = { version = "0.5.0", optional = true }
protox = { version = "0.6.0", optional = true }
2 changes: 1 addition & 1 deletion wkt-types/resources/lib.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#![doc(html_root_url = "https://docs.rs/prost-types/0.12.1")]
#![doc(html_root_url = "https://docs.rs/prost-types/0.12.2")]

//! Protocol Buffers well-known types.
//!
Expand Down
21 changes: 14 additions & 7 deletions wkt-types/src/pbtime/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -422,7 +422,7 @@ impl fmt::Display for Timestamp {
impl From<NaiveDateTime> for Timestamp {
fn from(dt: NaiveDateTime) -> Self {
Timestamp {
seconds: dt.timestamp(),
seconds: dt.and_utc().timestamp(),
nanos: dt.timestamp_subsec_nanos() as i32,
}
}
Expand All @@ -447,16 +447,23 @@ impl From<Timestamp> for DateTime<Utc> {
// deprecated in favour of TryFrom but unfortunately having `TryFrom` along with
// `From` causes a conflict.
value.normalize();
let dt = NaiveDateTime::from_timestamp_opt(value.seconds, value.nanos as u32)
.expect("invalid or out-of-range datetime");
DateTime::from_naive_utc_and_offset(dt, Utc)
DateTime::from_timestamp(value.seconds, value.nanos as u32)
.expect("invalid or out-of-range datetime")
}
}

/// Converts proto duration to chrono's Duration
impl From<Duration> for chrono::Duration {
fn from(val: Duration) -> Self {
chrono::Duration::seconds(val.seconds) + chrono::Duration::nanoseconds(val.nanos as i64)
let mut value = val;
// A call to `normalize` should capture all out-of-bound sitations hopefully
// ensuring a panic never happens! Ideally this implementation should be
// deprecated in favour of TryFrom but unfortunately having `TryFrom` along with
// `From` causes a conflict.
value.normalize();
let s = chrono::TimeDelta::try_seconds(value.seconds).expect("invalid or out-of-range seconds");
let ns = chrono::Duration::nanoseconds(value.nanos as i64);
s + ns
}
}

Expand Down Expand Up @@ -553,12 +560,12 @@ mod tests {
};
let chrono_duration: chrono::Duration = duration.into();
assert_eq!(chrono_duration.num_seconds(), 10);
assert_eq!((chrono_duration - chrono::Duration::seconds(10)).num_nanoseconds(), Some(100));
assert_eq!((chrono_duration - chrono::Duration::try_seconds(10).expect("seconds")).num_nanoseconds(), Some(100));
}

#[test]
fn test_duration_conversion_chrono_to_pb() {
let chrono_duration = chrono::Duration::seconds(10) + chrono::Duration::nanoseconds(100);
let chrono_duration = chrono::Duration::try_seconds(10).expect("seconds") + chrono::Duration::nanoseconds(100);
let duration: Duration = chrono_duration.into();
assert_eq!(duration.seconds, 10);
assert_eq!(duration.nanos, 100);
Expand Down

0 comments on commit bedabbb

Please sign in to comment.