Skip to content

Commit 906efae

Browse files
authored
RUST-811 Introduce feature flags for chrono and uuid interop (#347)
1 parent 7266083 commit 906efae

File tree

4 files changed

+12
-14
lines changed

4 files changed

+12
-14
lines changed

Cargo.toml

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,12 +29,16 @@ sync = ["async-std-runtime"]
2929
# whose implementation cannot be changed; otherwise, it is preferred to use the helper functions
3030
# provided in the bson::serde_helpers module.
3131
bson-u2i = ["bson/u2i"]
32+
# Enable support for v0.4 of the chrono crate in the public API of the BSON library.
33+
bson-chrono-0_4 = ["bson/chrono-0_4"]
34+
# Enable support for v0.8 of the uuid crate in the public API of the BSON library.
35+
bson-uuid-0_8 = ["bson/uuid-0_8"]
3236

3337
[dependencies]
3438
async-trait = "0.1.42"
3539
base64 = "0.13.0"
3640
bitflags = "1.1.0"
37-
bson = "2.0.0-beta"
41+
bson = { git = "https://github.com/mongodb/bson-rust" }
3842
chrono = "0.4.7"
3943
derivative = "2.1.1"
4044
futures-core = "0.3.14"

src/bson_util/mod.rs

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -277,11 +277,11 @@ mod test {
277277
spec::BinarySubtype,
278278
Binary,
279279
Bson,
280+
DateTime,
280281
JavaScriptCodeWithScope,
281282
Regex,
282283
Timestamp,
283284
};
284-
use chrono::{DateTime, NaiveDateTime, Utc};
285285

286286
use super::doc_size_bytes;
287287

@@ -309,10 +309,7 @@ mod test {
309309
"timestamp": Bson::Timestamp(Timestamp { time: 12233, increment: 34444 }),
310310
"binary": Bson::Binary(Binary{ subtype: BinarySubtype::Generic, bytes: vec![3, 222, 11] }),
311311
"objectid": ObjectId::from_bytes([1; 12]),
312-
"datetime": DateTime::from_utc(
313-
NaiveDateTime::from_timestamp(4444333221, 0),
314-
Utc,
315-
),
312+
"datetime": DateTime::from_millis(4444333221),
316313
"symbol": Bson::Symbol("foobar".into()),
317314
};
318315

src/sdam/description/server.rs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
11
use std::time::Duration;
22

3-
use crate::bson::{oid::ObjectId, DateTime};
4-
use chrono::offset::Utc;
5-
63
use crate::{
4+
bson::{oid::ObjectId, DateTime},
75
client::ClusterTime,
86
is_master::IsMasterReply,
97
options::ServerAddress,
@@ -115,7 +113,7 @@ impl ServerDescription {
115113
// We want to set last_update_time if we got any sort of response from the server.
116114
match description.reply {
117115
Ok(None) => {}
118-
_ => description.last_update_time = Some(Utc::now().into()),
116+
_ => description.last_update_time = Some(DateTime::now()),
119117
};
120118

121119
if let Ok(Some(ref mut reply)) = description.reply {

src/sdam/description/topology/server_selection/test/mod.rs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
use std::time::Duration;
22

3-
use bson::doc;
4-
use chrono::{TimeZone, Utc};
3+
use bson::{doc, DateTime};
54
use serde::Deserialize;
65

76
use crate::{
@@ -90,7 +89,7 @@ impl TestServerDescription {
9089
let mut command_response = is_master_response_from_server_type(server_type);
9190
command_response.tags = self.tags;
9291
command_response.last_write = self.last_write.map(|last_write| LastWrite {
93-
last_write_date: Utc.timestamp_millis(last_write.last_write_date).into(),
92+
last_write_date: DateTime::from_millis(last_write.last_write_date),
9493
});
9594

9695
let is_master = IsMasterReply {
@@ -105,7 +104,7 @@ impl TestServerDescription {
105104
);
106105
server_desc.last_update_time = self
107106
.last_update_time
108-
.map(|i| Utc.timestamp_millis(i.into()).into());
107+
.map(|i| DateTime::from_millis(i.into()));
109108

110109
Some(server_desc)
111110
}

0 commit comments

Comments
 (0)