-
Notifications
You must be signed in to change notification settings - Fork 190
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #550 from KodrAus/feat/arbitrary
Add optional arbitrary impl
- Loading branch information
Showing
17 changed files
with
92 additions
and
123 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,23 +1,20 @@ | ||
--- | ||
name: Feature request | ||
about: Suggest an idea for this project | ||
about: Suggest an idea for UUID | ||
|
||
--- | ||
|
||
**Is your feature request related to a problem? Please describe.** | ||
A clear and concise description of what the problem is. Ex. I'm always frustrated when [...] | ||
**Motivation** | ||
A clear and concise description of what the problem is. | ||
|
||
**Describe the solution you'd like** | ||
**Solution** | ||
A clear and concise description of what you want to happen. | ||
|
||
**Is it blocking?** | ||
Is this issue blocking any of your work? If it is blocking any open source project, you can share the link of the issue | ||
|
||
**Describe alternatives you've considered** | ||
**Alternatives** | ||
A clear and concise description of any alternative solutions or features you've considered. | ||
|
||
**Additional context** | ||
Add any other context or screenshots about the feature request here. | ||
**Is it blocking?** | ||
Is this issue blocking any of your work? If it is blocking any open source project, you can share the link of the issue | ||
|
||
**Other** | ||
**Anything else?** | ||
Other information like relevant issues, external links, etc |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,5 @@ | ||
<!-- | ||
If this PR is a breaking change, ensure that you are opening it against | ||
the `breaking` branch. If the pull request is incomplete, prepend the Title with WIP: | ||
--> | ||
|
||
**I'm submitting a(n)** (bug fix|deprecation|feature|refactor|removal|other) | ||
|
||
|
||
# Description | ||
|
||
# Motivation | ||
|
||
# Tests | ||
<!-- How are these changes tested? --> | ||
|
||
# Related Issue(s) |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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()); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
#[cfg(feature = "arbitrary")] | ||
mod arbitrary_support; | ||
#[cfg(feature = "serde")] | ||
mod serde_support; | ||
#[cfg(feature = "slog")] | ||
mod slog_support; |
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters