Skip to content

Commit

Permalink
Merge pull request #724 from bgeron/borsh-1
Browse files Browse the repository at this point in the history
Upgrade borsh unstable dependency to v1.0 and make it stable
  • Loading branch information
KodrAus committed Jan 18, 2024
2 parents 94ecea8 + 421d752 commit 2e92a3d
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 13 deletions.
19 changes: 14 additions & 5 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/external.rs
Original file line number Diff line number Diff line change
@@ -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;
Expand Down
5 changes: 2 additions & 3 deletions src/external/borsh_support.rs
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
#[cfg(test)]
mod borsh_tests {
use crate::Uuid;
use borsh::{BorshDeserialize, BorshSerialize};
use std::string::ToString;

#[test]
fn test_serialize() {
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);
}

Expand All @@ -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>(&uuid_bytes).unwrap().to_string();
assert_eq!(uuid_str, deserialized);
}
}
8 changes: 4 additions & 4 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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.
//!
Expand Down Expand Up @@ -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(
Expand Down

0 comments on commit 2e92a3d

Please sign in to comment.