diff --git a/Cargo.toml b/Cargo.toml index 3cdc6111..ead804a2 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -71,6 +71,8 @@ fast-rng = ["rng", "rand"] sha1 = ["sha1_smol"] md5 = ["md-5"] +borsh = ["dep:borsh", "dep:borsh-derive"] + # Public: Used in trait impls on `Uuid` [dependencies.bytemuck] @@ -103,13 +105,20 @@ version = "1.1.3" optional = true version = "0.6" -# Public (unstable): Used in trait impls on `Uuid` -# Unstable: also need RUSTFLAGS="--cfg uuid_unstable" to work -# This feature may break between releases, or be removed entirely before -# stabilization. +# Public: Used in trait impls on `Uuid` [dependencies.borsh] optional = true -version = "0.10.3" +version = "1" +default-features = false + +# Private +# Don't depend on this optional feature directly: it may change at any time +# use the `borsh` feature instead +[dependencies.borsh-derive] +package = "borsh-derive" +optional = true +version = "1" +default-features = false # Private # Don't depend on this optional feature directly: it may change at any time diff --git a/src/external.rs b/src/external.rs index 8ac12d0f..6f20d8fd 100644 --- a/src/external.rs +++ b/src/external.rs @@ -1,6 +1,6 @@ #[cfg(feature = "arbitrary")] pub(crate) mod arbitrary_support; -#[cfg(all(uuid_unstable, feature = "borsh"))] +#[cfg(feature = "borsh")] pub(crate) mod borsh_support; #[cfg(feature = "serde")] pub(crate) mod serde_support; diff --git a/src/external/borsh_support.rs b/src/external/borsh_support.rs index 24a177f3..f6f93c75 100644 --- a/src/external/borsh_support.rs +++ b/src/external/borsh_support.rs @@ -1,7 +1,6 @@ #[cfg(test)] mod borsh_tests { use crate::Uuid; - use borsh::{BorshDeserialize, BorshSerialize}; use std::string::ToString; #[test] @@ -9,7 +8,7 @@ mod borsh_tests { let uuid_str = "f9168c5e-ceb2-4faa-b6bf-329bf39fa1e4"; let uuid = Uuid::parse_str(uuid_str).unwrap(); let uuid_bytes = uuid.as_bytes().to_vec(); - let borsh_bytes = uuid.try_to_vec().unwrap(); + let borsh_bytes = borsh::to_vec(&uuid).unwrap(); assert_eq!(uuid_bytes, borsh_bytes); } @@ -18,7 +17,7 @@ mod borsh_tests { let uuid_str = "f9168c5e-ceb2-4faa-b6bf-329bf39fa1e4"; let uuid = Uuid::parse_str(uuid_str).unwrap(); let uuid_bytes = uuid.as_bytes().to_vec(); - let deserialized = Uuid::try_from_slice(&uuid_bytes).unwrap().to_string(); + let deserialized = borsh::from_slice::(&uuid_bytes).unwrap().to_string(); assert_eq!(uuid_str, deserialized); } } diff --git a/src/lib.rs b/src/lib.rs index 063db265..98b2939b 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -106,6 +106,8 @@ //! * `macro-diagnostics` - enhances the diagnostics of `uuid!` macro. //! * `serde` - adds the ability to serialize and deserialize a UUID using //! `serde`. +//! * `borsh` - adds the ability to serialize and deserialize a UUID using +//! `borsh`. //! * `arbitrary` - adds an `Arbitrary` trait implementation to `Uuid` for //! fuzzing. //! * `fast-rng` - uses a faster algorithm for generating random UUIDs. @@ -120,8 +122,6 @@ //! //! * `zerocopy` - adds support for zero-copy deserialization using the //! `zerocopy` library. -//! * `borsh` - adds the ability to serialize and deserialize a UUID using -//! `borsh`. //! //! Unstable features may break between minor releases. //! @@ -440,8 +440,8 @@ pub enum Variant { derive(AsBytes, FromBytes, Unaligned) )] #[cfg_attr( - all(uuid_unstable, feature = "borsh"), - derive(borsh::BorshDeserialize, borsh::BorshSerialize) + feature = "borsh", + derive(borsh_derive::BorshDeserialize, borsh_derive::BorshSerialize) )] #[repr(transparent)] #[cfg_attr(