Skip to content

Commit 7943d9b

Browse files
committed
Add Timestamp impls to get inner DateTime
1 parent 7bf1935 commit 7943d9b

File tree

1 file changed

+21
-1
lines changed

1 file changed

+21
-1
lines changed

rmp/src/lib.rs

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,34 @@ pub use crate::marker::Marker;
1414
pub const MSGPACK_VERSION: u32 = 5;
1515

1616
/// A type for holding Timestamp information
17-
#[derive(Debug, Copy, Clone, PartialEq, Eq)]
17+
#[derive(Debug, Clone, PartialEq, Eq)]
1818
#[cfg(feature = "chrono")]
1919
pub enum Timestamp {
2020
T32(chrono::DateTime<chrono::Utc>),
2121
T64(chrono::DateTime<chrono::Utc>),
2222
T96(chrono::DateTime<chrono::Utc>),
2323
}
2424

25+
impl Timestamp {
26+
/// Get the inner DateTime
27+
pub fn into_inner(self) -> chrono::DateTime<chrono::Utc> {
28+
match self {
29+
Self::T32(t) => t,
30+
Self::T64(t) => t,
31+
Self::T96(t) => t,
32+
}
33+
}
34+
35+
/// Get a reference to the inner DateTime
36+
pub fn as_datetime_ref(&self) -> &chrono::DateTime<chrono::Utc> {
37+
match self {
38+
Self::T32(t) => t,
39+
Self::T64(t) => t,
40+
Self::T96(t) => t,
41+
}
42+
}
43+
}
44+
2545
/// msgpack spec says nsecs must not be 1 billion or larger
2646
/// even though leap seconds can be just below 2 billion
2747
pub(crate) const MAX_NSECS: u32 = 999_999_999;

0 commit comments

Comments
 (0)