美文网首页Rust
外部包的导入

外部包的导入

作者: 空乱木 | 来源:发表于2019-10-26 20:44 被阅读0次

    0-参考链接
    https://rust-random.github.io/rand/rand/index.html

    1- cargo.toml 引用导入
    [dependencies]
    rand = “0.7.2"

    2- 代码use

    use rand::prelude::*;
    
    fn main() {
    
        if rand::random() { // generates a boolean
            // Try printing a random unicode code point (probably a bad idea)!
            println!("char: {}", rand::random::<char>());
        }
    
        let mut rng = rand::thread_rng();
        let y: f64 = rng.gen(); // generates a float between 0 and 1
    
        let mut nums: Vec<i32> = (1..100).collect();
        nums.shuffle(&mut rng);
        println!("Hello, world!");
    }
    

    3- 日志

    [@zhous-MBP-2:] ~/blockchain/rust/hello_cargo/src $ cargo run
    Finished dev [unoptimized + debuginfo] target(s) in 0.01s
    Running /Users/zhouhe/blockchain/rust/hello_cargo/target/debug/hello_cargo
    char: 񣞲
    Hello, world!

    相关文章

      网友评论

        本文标题:外部包的导入

        本文链接:https://www.haomeiwen.com/subject/mqpuvctx.html