Unable to implement quickchecks Arbitrarily for my own type - "source attribute is private"

I use quickcheck to check some properties of my code. At some point, I need an ASCII byte, so I tried to write an implementation Arbitraryas follows:

extern crate quickcheck;

use quickcheck::{quickcheck,Arbitrary,Gen};

#[derive(Debug,Copy,Clone)]
struct AsciiChar(u8);

impl Arbitrary for AsciiChar {
    fn arbitrary<G>(g: &mut G) -> AsciiChar
        where G: Gen
    {
        let a: u8 = g.gen_range(0, 128);
        AsciiChar(a)
    }
}

#[test]
fn it_works() {}

Error with error:

src/lib.rs:12:21: 12:40 error: source trait is private
src/lib.rs:12         let a: u8 = g.gen_range(0, 128);
                                  ^~~~~~~~~~~~~~~~~~~

Some searches led me to various error messages ( 1 , 2 , 3 , 4 ) that everything seems like I need a usesuperwrite Genthat rand::Rng. I updated my boxes and used instructions for

extern crate quickcheck;
extern crate rand;

use rand::Rng;
use quickcheck::{quickcheck,Arbitrary,Gen};

But I keep getting the same error.

I tried with

  • rustc version 1.1.0-dev (b402c43f0 2015-05-07) (built 2015-05-07)
  • rustc 1.1.0-dev (3ca008dcf 2015-05-12) (built 2015-05-12)

I also use quickcheck v0.2.18

0
source share
2

, . , :

impl Arbitrary for AsciiChar {
    fn arbitrary<G>(g: &mut G) -> AsciiChar
        where G: Gen
    {
        let a: u8 = Arbitrary::arbitrary(g);
        AsciiChar(a % 128)
    }
}

:

src/lib.rs:419:5: 419:23 error: use of unstable library feature 'rand': use `rand` from crates.io
src/lib.rs:419     extern crate rand;
                   ^~~~~~~~~~~~~~~~~~
src/lib.rs:419:5: 419:23 help: add #![feature(rand)] to the crate attributes to enable

, rand Cargo.toml. , , quickcheck.

, use d Rng, Gen. !

rand Cargo.toml, .

+3

. , :

extern crate quickcheck;
extern crate rand;

use quickcheck::{Arbitrary,Gen};
use rand::Rng;

#[derive(Debug,Copy,Clone)]
struct AsciiChar(u8);

impl Arbitrary for AsciiChar {
    fn arbitrary<G>(g: &mut G) -> AsciiChar
        where G: Gen
    {
        let a: u8 = g.gen_range(0, 128);
        AsciiChar(a)
    }
}

#[test]
fn it_works() {}

cargo test 5 2015-05-12 .

+1

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


All Articles