From a9b3402d0445ac9217a104b723710c6ab2553ffb Mon Sep 17 00:00:00 2001 From: yancy Date: Sat, 31 Aug 2024 08:04:08 -0500 Subject: [PATCH 1/2] draft: add arbitrary_in_range --- src/lib.rs | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/src/lib.rs b/src/lib.rs index 6ff98f3..2897a08 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -37,7 +37,7 @@ pub mod size_hint; use core::array; use core::cell::{Cell, RefCell, UnsafeCell}; use core::iter; -use core::mem; +use std::{mem, ops}; use core::num::{NonZeroI128, NonZeroI16, NonZeroI32, NonZeroI64, NonZeroI8, NonZeroIsize}; use core::num::{NonZeroU128, NonZeroU16, NonZeroU32, NonZeroU64, NonZeroU8, NonZeroUsize}; use core::ops::{Range, RangeBounds, RangeFrom, RangeInclusive, RangeTo, RangeToInclusive}; @@ -209,6 +209,15 @@ pub trait Arbitrary<'a>: Sized { /// See also the documentation for [`Unstructured`][crate::Unstructured]. fn arbitrary(u: &mut Unstructured<'a>) -> Result; + /// Generate an arbitrary value of `Self` for a given range from unstructured data. + fn arbitrary_in_range(u: &mut Unstructured<'a>, range: ops::RangeInclusive) -> Result + where + T: crate::unstructured::Int, + { + let _r = range; + Self::arbitrary(u) + } + /// Generate an arbitrary value of `Self` from the entirety of the given /// unstructured data. /// From 5d06035ac82aaec6add86f3c781a6c220ba00052 Mon Sep 17 00:00:00 2001 From: yancy Date: Sat, 31 Aug 2024 11:55:35 -0500 Subject: [PATCH 2/2] draft: Add to_u64 to Int --- src/unstructured.rs | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/unstructured.rs b/src/unstructured.rs index 639a1fc..2668ccf 100644 --- a/src/unstructured.rs +++ b/src/unstructured.rs @@ -832,6 +832,9 @@ pub trait Int: #[doc(hidden)] fn wrapping_add(self, rhs: Self) -> Self; + #[doc(hidden)] + fn to_u64(self) -> u64; + #[doc(hidden)] fn wrapping_sub(self, rhs: Self) -> Self; @@ -878,6 +881,10 @@ macro_rules! impl_int { self as $unsigned_ty } + fn to_u64(self) -> u64 { + self as u64 + } + fn from_unsigned(unsigned: $unsigned_ty) -> Self { unsigned as Self }