diff --git a/.cargo/config.toml b/.cargo/config.toml new file mode 100644 index 0000000..78bae9b --- /dev/null +++ b/.cargo/config.toml @@ -0,0 +1,2 @@ +[build] +rustflags = ["--cfg=uuid_unstable"] diff --git a/Cargo.toml b/Cargo.toml index 0f79bef..e798b13 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -13,12 +13,12 @@ rust-version = "1.67.1" [features] default = ["fast-rng"] -arbitrary = ["uuid/arbitrary", "arbitrary/derive"] # Add support for arbitrary types -random = ["uuid/v4"] # Create random ShortGuid IDs -fast-rng = ["random", "uuid/fast-rng"] # Use a faster (but still sufficiently random) RNG -serde = ["dep:serde", "uuid/serde"] # Serialization and deserialization support -# zerocopy = ["dep:zerocopy", "uuid/zerocopy"] # Zerocopy support -bytemuck = ["dep:bytemuck", "uuid/bytemuck"] # Bytemuck support +arbitrary = ["uuid/arbitrary", "arbitrary/derive"] # Add support for arbitrary types +random = ["uuid/v4"] # Create random ShortGuid IDs +fast-rng = ["random", "uuid/fast-rng"] # Use a faster (but still sufficiently random) RNG +serde = ["dep:serde", "uuid/serde"] # Serialization and deserialization support +zerocopy = ["dep:zerocopy", "uuid/zerocopy"] # Zerocopy support +bytemuck = ["dep:bytemuck", "uuid/bytemuck"] # Bytemuck support borsh = ["dep:borsh", "dep:borsh-derive", "uuid/borsh"] # Borsh support [[example]] @@ -42,7 +42,7 @@ zerocopy = { version = "0.7.33", optional = true, features = ["derive"] } [dev-dependencies] hex = "0.4.3" -clap = "4.5.4" +clap = "4.4.11" serde_test = "1.0.176" [package.metadata.docs.rs] diff --git a/src/lib.rs b/src/lib.rs index babdc9b..552a4aa 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -41,6 +41,9 @@ use std::fmt::{Debug, Display, Formatter}; use std::str::FromStr; use uuid::Uuid; +#[cfg(all(uuid_unstable, feature = "zerocopy"))] +use zerocopy::{AsBytes, FromBytes, Unaligned}; + /// A short, URL-safe UUID representation. /// /// ## Example @@ -67,10 +70,10 @@ use uuid::Uuid; /// ``` #[derive(Default, Copy, Clone, Eq, PartialEq, Hash, Ord, PartialOrd)] #[cfg_attr(feature = "arbitrary", derive(arbitrary::Arbitrary))] -// #[cfg_attr( -// feature = "zerocopy", -// derive(zerocopy::AsBytes, zerocopy::FromBytes, zerocopy::Unaligned) -// )] +#[cfg_attr( + all(uuid_unstable, feature = "zerocopy"), + derive(AsBytes, FromBytes, Unaligned) +)] #[cfg_attr( feature = "borsh", derive(borsh_derive::BorshDeserialize, borsh_derive::BorshSerialize)