I have the following code, where I try to implement Rng and RngCore for a custom type.
#[cfg(test)]
use rand::{Rng, RngCore};
pub const FP751_NUM_WORDS: usize = 12;
#[repr(C)]
#[derive(Copy, Clone)]
pub struct Fp751Element(pub (crate) [u64; FP751_NUM_WORDS]);
#[cfg(test)]
impl RngCore for Fp751Element {
fn next_u64(&mut self) -> u64 {
self.next_u64()
}
}
#[cfg(test)]
impl Rng for Fp751Element {
fn gen<Fp751Element>(&mut self) -> Fp751Element {
let high_limb = self.next_u64() % 246065832128056;
Fp751Element([
self.next_u64(),
self.next_u64(),
self.next_u64(),
self.next_u64(),
self.next_u64(),
self.next_u64(),
self.next_u64(),
self.next_u64(),
self.next_u64(),
self.next_u64(),
self.next_u64(),
high_limb
])
}
}
I want to implement the traits because I later want to use the quickcheck::Arbitrary with my type. However, the above type code throws the following error at impl Rng for Fp751Element line:
conflicting implementation in crate
rand: - impl rand::Rng for R where R: rand::RngCore, R: ?Sized;
Any ideas?