Skip to content

Commit

Permalink
Implement Arbitrary for core::cmp::Reverse
Browse files Browse the repository at this point in the history
  • Loading branch information
swwu committed Dec 5, 2024
1 parent cd62300 commit 05de6a5
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 0 deletions.
23 changes: 23 additions & 0 deletions src/foreign/core/cmp.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
use {
crate::{size_hint, Arbitrary, Result, Unstructured},
core::cmp::Reverse,
};

impl<'a, A> Arbitrary<'a> for Reverse<A>
where
A: Arbitrary<'a>,
{
fn arbitrary(u: &mut Unstructured<'a>) -> Result<Self> {
Arbitrary::arbitrary(u).map(Self)
}

#[inline]
fn size_hint(depth: usize) -> (usize, Option<usize>) {
Self::try_size_hint(depth).unwrap_or_default()
}

#[inline]
fn try_size_hint(depth: usize) -> Result<(usize, Option<usize>), crate::MaxRecursionReached> {
size_hint::try_recursion_guard(depth, <A as Arbitrary>::try_size_hint)
}
}
1 change: 1 addition & 0 deletions src/foreign/core/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ mod array;
mod bool;
mod cell;
mod char;
mod cmp;
mod iter;
mod marker;
mod num;
Expand Down

0 comments on commit 05de6a5

Please sign in to comment.