Sha256: 13ea4aab756af7de3e1cc1e38aa0a68045c213636809862193a047c36f13f0a7

Contents?: true

Size: 925 Bytes

Versions: 3

Compression:

Stored size: 925 Bytes

Contents

use crate::{size_hint, Arbitrary, Error, MaxRecursionReached, Unstructured};

impl<'a, T, E> Arbitrary<'a> for Result<T, E>
where
    T: Arbitrary<'a>,
    E: Arbitrary<'a>,
{
    fn arbitrary(u: &mut Unstructured<'a>) -> Result<Self, Error> {
        Ok(if <bool as Arbitrary<'a>>::arbitrary(u)? {
            Ok(<T as Arbitrary>::arbitrary(u)?)
        } else {
            Err(<E as Arbitrary>::arbitrary(u)?)
        })
    }

    #[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>), MaxRecursionReached> {
        Ok(size_hint::and(
            <bool as Arbitrary>::size_hint(depth),
            size_hint::or(
                <T as Arbitrary>::try_size_hint(depth)?,
                <E as Arbitrary>::try_size_hint(depth)?,
            ),
        ))
    }
}

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
wasmtime-29.0.0 ./ext/cargo-vendor/arbitrary-1.4.1/src/foreign/core/result.rs
wasmtime-28.0.0 ./ext/cargo-vendor/arbitrary-1.4.1/src/foreign/core/result.rs
wasmtime-27.0.0 ./ext/cargo-vendor/arbitrary-1.4.1/src/foreign/core/result.rs