< 返回版块

豆沙饼 is Louys 发表于 2022-12-08 10:40

问题已解决,是因为fake 2.3.0 只能用rand="^0.7.0"

let mut r = rand::thread_rng();
SafeEmail().fake_with_rng(&mut r);

==========================================================

Cargo.toml

fake = "2.3.0"
rand = "0.8.5"

请各位大佬指教一下。 对Trait有疑问,怎么才能生成一个R: Rng + ?Sized, 使得代码能正常编译,并生成一个随机的邮件地址. 使用的是Fack crate

use fake::Fake;
use fake::faker::internet::en::SafeEmail;
fn main(){
    let mut r = rand::thread_rng();
    let g = g //这里怎么写??????
    let email : String = SafeEmail().fake_with_rng(g);
    println!("{}", email);
}

fake_with_rng 函数签名如下

fake::Fake
pub fn fake_with_rng<U, R>(&self, rng: &mut R) -> U
where
    R: Rng + ?Sized,
    Self: private::FakeBase<U>,

评论区

写评论
苦瓜小仔 2022-12-08 11:16

代码

    let mut r = rand::thread_rng();
    let email : String = SafeEmail().fake_with_rng(&mut r);
1 共 1 条评论, 1 页