How to avoid using the source attribute when using subtractions?

I am trying to use quickcheck in Rust. I want to define my enum as an instance Arbitrary, so I can use it in tests.

#![feature(plugin)]
#![plugin(quickcheck_macros)]

#[cfg(test)]
extern crate quickcheck;

use quickcheck::{Arbitrary,Gen};

#[derive(Clone)]
enum Animal {
    Cat,
    Dog,
    Mouse
}

impl Arbitrary for Animal {
    fn arbitrary<G: Gen>(g: &mut G) -> Animal {
        let i = g.next_u32();
        match i % 3 {
            0 => Animal::Cat,
            1 => Animal::Dog,
            2 => Animal::Mouse,
        }
    }
}

However, this gives me a compilation error:

src/main.rs:18:17: 18:29 error: source trait is private
src/main.rs:18         let i = g.next_u32();
                               ^~~~~~~~~~~~

What causes this error? I know that this problem is with rust , but since it is Genimported, I would think what I can call .next_u32.

+4
source share
1 answer

It looks like it Genhas rand::Rnga parent trait, it works if you add extern crate randafter adding rand = "*"to your Cargo.toml.

[ #[cfg(test)] quickcheck import]

+3

Source: https://habr.com/ru/post/1598457/


All Articles