Skip to content

Commit 2944e77

Browse files
authored
RUST-1305 Add support for version 1.x of the uuid crate to the bson crate (#362)
1 parent 34dd74f commit 2944e77

15 files changed

+441
-180
lines changed

.evergreen/check-clippy.sh

+4-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
1-
#!/bin/sh
1+
#!/bin/bash
22

33
set -o errexit
44

55
. ~/.cargo/env
6+
67
cargo clippy --all-targets --all-features -p bson -- -D warnings
78

8-
cd serde-tests && cargo clippy --all-targets --all-features -p serde-tests -- -D warnings
9+
cd serde-tests
10+
cargo clippy --all-targets --all-features -p serde-tests -- -D warnings

.evergreen/check-rustdoc.sh

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
1-
#!/bin/sh
1+
#!/bin/bash
22

33
set -o errexit
44

55
. ~/.cargo/env
6-
cargo +nightly rustdoc -p bson --all-features -- --cfg docsrs -D warnings
6+
7+
cargo +nightly rustdoc -p bson --all-features -- --cfg docsrs -D warnings

.evergreen/check-rustfmt.sh

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#!/bin/sh
1+
#!/bin/bash
22

33
set -o errexit
44

.evergreen/compile-only.sh

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#!/bin/sh
1+
#!/bin/bash
22

33
set -o errexit
44

.evergreen/install-dependencies.sh

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#!/bin/sh
1+
#!/bin/bash
22

33
rm -rf ~/.rustup
44
curl https://sh.rustup.rs -sSf | sh -s -- -y --no-modify-path

.evergreen/install-fuzzer.sh

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#!/bin/sh
1+
#!/bin/bash
22

33
set -o errexit
44

.evergreen/run-fuzzer.sh

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#!/bin/sh
1+
#!/bin/bash
22

33
set -o errexit
44

.evergreen/run-tests.sh

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
1-
#!/bin/sh
1+
#!/bin/bash
22

33
set -o errexit
44

55
. ~/.cargo/env
6+
67
RUST_BACKTRACE=1 cargo test
78
RUST_BACKTRACE=1 cargo test --all-features
89

Cargo.toml

+7-2
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,11 @@ default = []
3535
# if enabled, include API for interfacing with chrono 0.4
3636
chrono-0_4 = ["chrono"]
3737
# if enabled, include API for interfacing with uuid 0.8
38-
uuid-0_8 = []
38+
# This is commented out because Cargo implicitly adds this feature since
39+
# uuid-0_8 is also an optional dependency.
40+
# uuid-0_8 = []
41+
# if enabled, include API for interfacing with uuid 1.x
42+
uuid-1 = []
3943
# if enabled, include API for interfacing with time 0.3
4044
time-0_3 = []
4145
# if enabled, include serde_with interop.
@@ -57,7 +61,8 @@ indexmap = "1.6.2"
5761
hex = "0.4.2"
5862
base64 = "0.13.0"
5963
lazy_static = "1.4.0"
60-
uuid = { version = "0.8.1", features = ["serde", "v4"] }
64+
uuid-0_8 = { package = "uuid", version = "0.8.1", features = ["serde", "v4"], optional = true }
65+
uuid = { version = "1.1.2", features = ["serde", "v4"] }
6166
serde_bytes = "0.11.5"
6267
serde_with = { version = "1", optional = true }
6368
time = { version = "0.3.9", features = ["formatting", "parsing", "macros", "large-dates"] }

README.md

+1
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ Note that if you are using `bson` through the `mongodb` crate, you do not need t
4848
|:-------------|:----------------------------------------------------------------------------------------------------|:-------------------|:--------|
4949
| `chrono-0_4` | Enable support for v0.4 of the [`chrono`](docs.rs/chrono/0.4) crate in the public API. | n/a | no |
5050
| `uuid-0_8` | Enable support for v0.8 of the [`uuid`](docs.rs/uuid/0.8) crate in the public API. | n/a | no |
51+
| `uuid-1` | Enable support for v1.x of the [`uuid`](docs.rs/uuid/1.0) crate in the public API. | n/a | no |
5152
| `serde_with` | Enable [`serde_with`](docs.rs/serde_with/latest) integrations for `bson::DateTime` and `bson::Uuid` | serde_with | no |
5253

5354
## Overview of the BSON Format

src/bson.rs

+8
Original file line numberDiff line numberDiff line change
@@ -328,6 +328,14 @@ impl<T: chrono::TimeZone> From<chrono::DateTime<T>> for Bson {
328328

329329
#[cfg(feature = "uuid-0_8")]
330330
#[cfg_attr(docsrs, doc(cfg(feature = "uuid-0_8")))]
331+
impl From<uuid_0_8::Uuid> for Bson {
332+
fn from(uuid: uuid_0_8::Uuid) -> Self {
333+
Bson::Binary(uuid.into())
334+
}
335+
}
336+
337+
#[cfg(feature = "uuid-1")]
338+
#[cfg_attr(docsrs, doc(cfg(feature = "uuid-1")))]
331339
impl From<uuid::Uuid> for Bson {
332340
fn from(uuid: uuid::Uuid) -> Self {
333341
Bson::Binary(uuid.into())

0 commit comments

Comments
 (0)