Skip to content

Commit 7921a71

Browse files
RUST-390 Implement ordering for Timestamp (#182)
1 parent ccb6827 commit 7921a71

File tree

2 files changed

+21
-1
lines changed

2 files changed

+21
-1
lines changed

src/bson.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -985,7 +985,7 @@ impl Bson {
985985
}
986986

987987
/// Represents a BSON timestamp value.
988-
#[derive(Debug, Eq, PartialEq, Clone, Copy, Hash)]
988+
#[derive(Debug, Eq, Ord, PartialEq, PartialOrd, Clone, Copy, Hash)]
989989
pub struct Timestamp {
990990
/// The number of seconds since the Unix epoch.
991991
pub time: u32,

tests/modules/bson.rs

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ use bson::{
77
Document,
88
JavaScriptCodeWithScope,
99
Regex,
10+
Timestamp,
1011
};
1112
use serde_json::{json, Value};
1213

@@ -140,3 +141,22 @@ fn from_impls() {
140141
let db_pointer = db_pointer.as_db_pointer().unwrap();
141142
assert_eq!(Bson::from(db_pointer), Bson::DbPointer(db_pointer.clone()));
142143
}
144+
145+
#[test]
146+
fn timestamp_ordering() {
147+
let ts1 = Timestamp {
148+
time: 0,
149+
increment: 1,
150+
};
151+
let ts2 = Timestamp {
152+
time: 0,
153+
increment: 2,
154+
};
155+
let ts3 = Timestamp {
156+
time: 1,
157+
increment: 0,
158+
};
159+
assert!(ts1 < ts2);
160+
assert!(ts1 < ts3);
161+
assert!(ts2 < ts3);
162+
}

0 commit comments

Comments
 (0)