Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand Down Expand Up @@ -209,6 +209,15 @@ pub trait Arbitrary<'a>: Sized {
/// See also the documentation for [`Unstructured`][crate::Unstructured].
fn arbitrary(u: &mut Unstructured<'a>) -> Result<Self>;

/// Generate an arbitrary value of `Self` for a given range from unstructured data.
fn arbitrary_in_range<T>(u: &mut Unstructured<'a>, range: ops::RangeInclusive<T>) -> Result<Self>
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.
///
Expand Down
7 changes: 7 additions & 0 deletions src/unstructured.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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
}
Expand Down