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. /// 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 }