Skip to content

RUST-1380 Drop support for uuid 0.8 #534

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
May 19, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 1 addition & 12 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 0 additions & 5 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,6 @@ exclude = [
default = []
# if enabled, include API for interfacing with chrono 0.4
chrono-0_4 = ["chrono"]
# if enabled, include API for interfacing with uuid 0.8
# This is commented out because Cargo implicitly adds this feature since
# uuid-0_8 is also an optional dependency.
# uuid-0_8 = []
# if enabled, include API for interfacing with uuid 1.x
uuid-1 = []
# if enabled, include API for interfacing with time 0.3
Expand Down Expand Up @@ -69,7 +65,6 @@ indexmap = "2.1.0"
hex = "0.4.2"
base64 = "0.22.1"
once_cell = "1.5.1"
uuid-0_8 = { package = "uuid", version = "0.8.1", features = ["serde", "v4"], optional = true }
uuid = { version = "1.1.2", features = ["serde", "v4"] }
serde_bytes = "0.11.5"
serde_with = { version = "1.3.1", optional = true }
Expand Down
1 change: 0 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,6 @@ Note that if you are using `bson` through the `mongodb` crate, you do not need t
| Feature | Description | Extra dependencies | Default |
| :----------- | :---------------------------------------------------------------------------------------------------------- | :----------------- | :------ |
| `chrono-0_4` | Enable support for v0.4 of the [`chrono`](https://docs.rs/chrono/0.4) crate in the public API. | n/a | no |
| `uuid-0_8` | Enable support for v0.8 of the [`uuid`](https://docs.rs/uuid/0.8) crate in the public API. | n/a | no |
| `uuid-1` | Enable support for v1.x of the [`uuid`](https://docs.rs/uuid/1.0) crate in the public API. | n/a | no |
| `time-0_3` | Enable support for v0.3 of the [`time`](https://docs.rs/time/0.3) crate in the public API. | n/a | no |
| `serde_with` | Enable [`serde_with`](https://docs.rs/serde_with/1.x) 1.x integrations for `bson::DateTime` and `bson::Uuid`.| serde_with | no |
Expand Down
15 changes: 2 additions & 13 deletions serde-tests/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions serde-tests/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,13 @@ edition = "2018"
default = []

[dependencies]
bson = { path = "..", features = ["uuid-0_8", "chrono-0_4", "serde_with"] }
bson = { path = "..", features = ["uuid-1", "chrono-0_4", "serde_with"] }
serde = { version = "1.0", features = ["derive"] }
pretty_assertions = "0.6.1"
hex = "0.4.2"
serde_with = "1"
chrono = "0.4"
uuid = "0.8"
uuid = "1"

[dev-dependencies]
serde_json = "1"
Expand Down
8 changes: 0 additions & 8 deletions src/bson.rs
Original file line number Diff line number Diff line change
Expand Up @@ -414,14 +414,6 @@ impl<T: chrono::TimeZone> From<chrono::DateTime<T>> for Bson {
}
}

#[cfg(feature = "uuid-0_8")]
#[cfg_attr(docsrs, doc(cfg(feature = "uuid-0_8")))]
impl From<uuid_0_8::Uuid> for Bson {
fn from(uuid: uuid_0_8::Uuid) -> Self {
Bson::Binary(uuid.into())
}
}

#[cfg(feature = "uuid-1")]
#[cfg_attr(docsrs, doc(cfg(feature = "uuid-1")))]
impl From<uuid::Uuid> for Bson {
Expand Down
131 changes: 0 additions & 131 deletions src/serde_helpers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -83,30 +83,6 @@ pub use uuid_1_as_python_legacy_binary::{
deserialize as deserialize_uuid_1_from_python_legacy_binary,
serialize as serialize_uuid_1_as_python_legacy_binary,
};
#[cfg(feature = "uuid-0_8")]
#[doc(inline)]
pub use uuid_as_binary::{
deserialize as deserialize_uuid_from_binary,
serialize as serialize_uuid_as_binary,
};
#[cfg(feature = "uuid-0_8")]
#[doc(inline)]
pub use uuid_as_c_sharp_legacy_binary::{
deserialize as deserialize_uuid_from_c_sharp_legacy_binary,
serialize as serialize_uuid_as_c_sharp_legacy_binary,
};
#[cfg(feature = "uuid-0_8")]
#[doc(inline)]
pub use uuid_as_java_legacy_binary::{
deserialize as deserialize_uuid_from_java_legacy_binary,
serialize as serialize_uuid_as_java_legacy_binary,
};
#[cfg(feature = "uuid-0_8")]
#[doc(inline)]
pub use uuid_as_python_legacy_binary::{
deserialize as deserialize_uuid_from_python_legacy_binary,
serialize as serialize_uuid_as_python_legacy_binary,
};

/// Attempts to serialize a u32 as an i32. Errors if an exact conversion is not possible.
pub fn serialize_u32_as_i32<S: Serializer>(val: &u32, serializer: S) -> Result<S::Ok, S::Error> {
Expand Down Expand Up @@ -527,29 +503,6 @@ macro_rules! as_binary_mod {
};
}

/// Contains functions to serialize a [`uuid_0_8::Uuid`] as a [`crate::Binary`] and deserialize a
/// [`uuid_0_8::Uuid`] from a [`crate::Binary`].
///
/// ```rust
/// # #[cfg(feature = "uuid-0_8")]
/// # {
/// use serde::{Serialize, Deserialize};
/// use uuid_0_8::Uuid;
/// use bson::serde_helpers::uuid_as_binary;
///
/// #[derive(Serialize, Deserialize)]
/// struct Item {
/// #[serde(with = "uuid_as_binary")]
/// pub id: Uuid,
/// }
/// # }
/// ```
#[cfg(feature = "uuid-0_8")]
#[cfg_attr(docsrs, doc(cfg(feature = "uuid-0_8")))]
pub mod uuid_as_binary {
as_binary_mod!(cfg(feature = "uuid-0_8"), uuid_0_8::Uuid);
}

/// Contains functions to serialize a [`uuid::Uuid`] as a [`crate::Binary`] and deserialize a
/// [`uuid::Uuid`] from a [`crate::Binary`].
///
Expand Down Expand Up @@ -603,34 +556,6 @@ macro_rules! as_legacy_binary_mod {
};
}

/// Contains functions to serialize a [`uuid_0_8::Uuid`] to a [`crate::Binary`] in the legacy
/// Java driver UUID format and deserialize [`uuid_0_8::Uuid`] from a [`crate::Binary`] in the
/// legacy Java driver format.
///
/// ```rust
/// #[cfg(feature = "uuid-0_8")]
/// # {
/// use serde::{Serialize, Deserialize};
/// use uuid_0_8::Uuid;
/// use bson::serde_helpers::uuid_as_java_legacy_binary;
///
/// #[derive(Serialize, Deserialize)]
/// struct Item {
/// #[serde(with = "uuid_as_java_legacy_binary")]
/// pub id: Uuid,
/// }
/// # }
/// ```
#[cfg(feature = "uuid-0_8")]
#[cfg_attr(docsrs, doc(cfg(feature = "uuid-0_8")))]
pub mod uuid_as_java_legacy_binary {
as_legacy_binary_mod!(
cfg(feature = "uuid-0_8"),
uuid_0_8::Uuid,
UuidRepresentation::JavaLegacy
);
}

/// Contains functions to serialize a [`uuid::Uuid`] to a [`crate::Binary`] in the legacy
/// Java driver UUID format and deserialize [`uuid::Uuid`] from a [`crate::Binary`] in the legacy
/// Java driver format.
Expand Down Expand Up @@ -659,34 +584,6 @@ pub mod uuid_1_as_java_legacy_binary {
);
}

/// Contains functions to serialize a [`uuid_0_8::Uuid`] to a [`crate::Binary`] in the legacy Python
/// driver UUID format and deserialize [`uuid_0_8::Uuid`] from a [`crate::Binary`] in the legacy
/// Python driver format.
///
/// ```rust
/// # #[cfg(feature = "uuid-0_8")]
/// # {
/// use serde::{Serialize, Deserialize};
/// use uuid_0_8::Uuid;
/// use bson::serde_helpers::uuid_as_python_legacy_binary;
///
/// #[derive(Serialize, Deserialize)]
/// struct Item {
/// #[serde(with = "uuid_as_python_legacy_binary")]
/// pub id: Uuid,
/// }
/// # }
/// ```
#[cfg(feature = "uuid-0_8")]
#[cfg_attr(docsrs, doc(cfg(feature = "uuid-0_8")))]
pub mod uuid_as_python_legacy_binary {
as_legacy_binary_mod!(
cfg(feature = "uuid-0_8"),
uuid_0_8::Uuid,
UuidRepresentation::PythonLegacy
);
}

/// Contains functions to serialize a [`uuid::Uuid`] to a [`crate::Binary`] in the legacy Python
/// driver UUID format and deserialize [`uuid::Uuid`] from a [`crate::Binary`] in the legacy Python
/// driver format.
Expand Down Expand Up @@ -715,34 +612,6 @@ pub mod uuid_1_as_python_legacy_binary {
);
}

/// Contains functions to serialize a [`uuid_0_8::Uuid`] to a [`crate::Binary`] in the legacy C#
/// driver UUID format and deserialize [`uuid_0_8::Uuid`] from a [`crate::Binary`] in the legacy C#
/// driver format.
///
/// ```rust
/// # #[cfg(feature = "uuid-0_8")]
/// # {
/// use serde::{Serialize, Deserialize};
/// use uuid_0_8::Uuid;
/// use bson::serde_helpers::uuid_as_c_sharp_legacy_binary;
///
/// #[derive(Serialize, Deserialize)]
/// struct Item {
/// #[serde(with = "uuid_as_c_sharp_legacy_binary")]
/// pub id: Uuid,
/// }
/// # }
/// ```
#[cfg(feature = "uuid-0_8")]
#[cfg_attr(docsrs, doc(cfg(feature = "uuid-0_8")))]
pub mod uuid_as_c_sharp_legacy_binary {
as_legacy_binary_mod!(
cfg(feature = "uuid-0_8"),
uuid_0_8::Uuid,
UuidRepresentation::CSharpLegacy
);
}

/// Contains functions to serialize a [`uuid::Uuid`] to a [`crate::Binary`] in the legacy C# driver
/// UUID format and deserialize [`uuid::Uuid`] from a [`crate::Binary`] in the legacy C# driver
/// format.
Expand Down
76 changes: 0 additions & 76 deletions src/tests/serde.rs
Original file line number Diff line number Diff line change
Expand Up @@ -554,54 +554,6 @@ fn test_de_db_pointer() {
assert_eq!(foo.db_pointer, db_pointer.clone());
}

#[cfg(feature = "uuid-0_8")]
#[test]
fn test_serde_legacy_uuid_0_8() {
use uuid_0_8::Uuid;

let _guard = LOCK.run_concurrently();

#[derive(Serialize, Deserialize)]
struct Foo {
#[serde(with = "serde_helpers::uuid_as_java_legacy_binary")]
java_legacy: Uuid,
#[serde(with = "serde_helpers::uuid_as_python_legacy_binary")]
python_legacy: Uuid,
#[serde(with = "serde_helpers::uuid_as_c_sharp_legacy_binary")]
csharp_legacy: Uuid,
}
let uuid = Uuid::parse_str("00112233445566778899AABBCCDDEEFF").unwrap();
let foo = Foo {
java_legacy: uuid,
python_legacy: uuid,
csharp_legacy: uuid,
};

let x = to_bson(&foo).unwrap();
assert_eq!(
x.as_document().unwrap(),
&doc! {
"java_legacy": Bson::Binary(Binary{
subtype:BinarySubtype::UuidOld,
bytes: hex::decode("7766554433221100FFEEDDCCBBAA9988").unwrap(),
}),
"python_legacy": Bson::Binary(Binary{
subtype:BinarySubtype::UuidOld,
bytes: hex::decode("00112233445566778899AABBCCDDEEFF").unwrap(),
}),
"csharp_legacy": Bson::Binary(Binary{
subtype:BinarySubtype::UuidOld,
bytes: hex::decode("33221100554477668899AABBCCDDEEFF").unwrap(),
})
}
);

let foo: Foo = from_bson(x).unwrap();
assert_eq!(foo.java_legacy, uuid);
assert_eq!(foo.python_legacy, uuid);
assert_eq!(foo.csharp_legacy, uuid);
}

#[cfg(feature = "uuid-1")]
#[test]
fn test_serde_legacy_uuid_1() {
Expand Down Expand Up @@ -988,34 +940,6 @@ fn test_i64_as_bson_datetime() {
assert_eq!(a.now, now.timestamp_millis());
}

#[test]
#[cfg(feature = "uuid-0_8")]
fn test_uuid_0_8_helpers() {
use serde_helpers::uuid_as_binary;
use uuid_0_8::Uuid;

let _guard = LOCK.run_concurrently();

#[derive(Serialize, Deserialize)]
struct A {
#[serde(with = "uuid_as_binary")]
uuid: Uuid,
}

let uuid = Uuid::parse_str("936DA01F9ABD4d9d80C702AF85C822A8").unwrap();
let a = A { uuid };
let doc = to_document(&a).unwrap();
match doc.get("uuid").unwrap() {
Bson::Binary(bin) => {
assert_eq!(bin.subtype, BinarySubtype::Uuid);
assert_eq!(bin.bytes, uuid.as_bytes());
}
_ => panic!("expected Bson::Binary"),
}
let a: A = from_document(doc).unwrap();
assert_eq!(a.uuid, uuid);
}

#[test]
#[cfg(feature = "uuid-1")]
fn test_uuid_1_helpers() {
Expand Down
Loading