Skip to content

Commit

Permalink
Check for invalid cast
Browse files Browse the repository at this point in the history
  • Loading branch information
pitdicker committed Jan 31, 2024
1 parent 247b653 commit 27fa337
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion src/naive/datetime/serde.rs
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,9 @@ assert_eq!(my_s.time, time);
expecting: "a unix timestamp",
visit_i64(i64): |value: i64| NaiveDateTime::from_timestamp_opt(value, 0)
.ok_or_else(|| E::custom(ne_timestamp(value))),
visit_u64(u64): |value: u64| NaiveDateTime::from_timestamp_opt(value as i64, 0)
visit_u64(u64): |value: u64| i64::try_from(value)
.ok()
.and_then(|v| NaiveDateTime::from_timestamp_opt(v, 0))
.ok_or_else(|| E::custom(ne_timestamp(value))),
}

Expand Down

0 comments on commit 27fa337

Please sign in to comment.