mirror of
https://github.com/uuid-rs/uuid.git
synced 2025-10-02 15:24:57 +00:00
move external impls to new module
This commit is contained in:
parent
93ead9b498
commit
477e26e318
@ -117,7 +117,6 @@ version = "2"
|
||||
[dependencies.arbitrary]
|
||||
optional = true
|
||||
version = "1"
|
||||
features = ["derive"]
|
||||
|
||||
# Public (unstable): Used in `zerocopy` derive
|
||||
[dependencies.zerocopy]
|
||||
|
@ -53,10 +53,7 @@ fn guid_to_uuid() {
|
||||
#[cfg(windows)]
|
||||
fn uuid_from_cocreateguid() {
|
||||
use uuid::{Uuid, Variant, Version};
|
||||
use winapi::{
|
||||
shared::guiddef,
|
||||
um::combaseapi::CoCreateGuid,
|
||||
};
|
||||
use winapi::{shared::guiddef, um::combaseapi::CoCreateGuid};
|
||||
|
||||
let mut guid = guiddef::GUID::default();
|
||||
|
||||
|
43
src/external/arbitrary_support.rs
vendored
Normal file
43
src/external/arbitrary_support.rs
vendored
Normal file
@ -0,0 +1,43 @@
|
||||
use crate::{std::convert::TryInto, Builder, Uuid};
|
||||
|
||||
use arbitrary::{Arbitrary, Unstructured};
|
||||
|
||||
impl Arbitrary<'_> for Uuid {
|
||||
fn arbitrary(u: &mut Unstructured<'_>) -> arbitrary::Result<Self> {
|
||||
let b = u
|
||||
.bytes(16)?
|
||||
.try_into()
|
||||
.map_err(|_| arbitrary::Error::NotEnoughData)?;
|
||||
|
||||
Ok(Builder::from_random_bytes(b).into_uuid())
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
|
||||
use crate::{Variant, Version};
|
||||
|
||||
#[test]
|
||||
fn test_arbitrary() {
|
||||
let mut bytes = Unstructured::new(&[
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||
]);
|
||||
|
||||
let uuid = Uuid::arbitrary(&mut bytes).unwrap();
|
||||
|
||||
assert_eq!(Some(Version::Random), uuid.get_version());
|
||||
assert_eq!(Variant::RFC4122, uuid.get_variant());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_arbitrary_empty() {
|
||||
let mut bytes = Unstructured::new(&[]);
|
||||
|
||||
// Ensure we don't panic when building an arbitrary `Uuid`
|
||||
let uuid = Uuid::arbitrary(&mut bytes);
|
||||
|
||||
assert!(uuid.is_err());
|
||||
}
|
||||
}
|
6
src/external/mod.rs
vendored
Normal file
6
src/external/mod.rs
vendored
Normal file
@ -0,0 +1,6 @@
|
||||
#[cfg(feature = "arbitrary")]
|
||||
mod arbitrary_support;
|
||||
#[cfg(feature = "serde")]
|
||||
mod serde_support;
|
||||
#[cfg(feature = "slog")]
|
||||
mod slog_support;
|
10
src/lib.rs
10
src/lib.rs
@ -190,9 +190,6 @@ compile_error!("The `zerocopy-unstable` feature is unstable and may break betwee
|
||||
#[cfg(feature = "zerocopy-unstable")]
|
||||
use zerocopy::{AsBytes, FromBytes, Unaligned};
|
||||
|
||||
#[cfg(feature = "arbitrary")]
|
||||
use arbitrary::Arbitrary;
|
||||
|
||||
mod builder;
|
||||
mod error;
|
||||
mod parser;
|
||||
@ -210,10 +207,8 @@ mod v5;
|
||||
|
||||
#[cfg(feature = "rng")]
|
||||
mod rng;
|
||||
#[cfg(feature = "serde")]
|
||||
mod serde_support;
|
||||
#[cfg(feature = "slog")]
|
||||
mod slog_support;
|
||||
|
||||
mod external;
|
||||
|
||||
#[cfg(feature = "macros")]
|
||||
#[macro_use]
|
||||
@ -359,7 +354,6 @@ pub enum Variant {
|
||||
feature = "zerocopy-unstable",
|
||||
derive(AsBytes, FromBytes, Unaligned)
|
||||
)]
|
||||
#[cfg_attr(feature = "arbitrary", derive(Arbitrary))]
|
||||
#[repr(transparent)]
|
||||
pub struct Uuid(Bytes);
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user