Rust 标准库

发布时间: 更新时间: 总字数:99 阅读时间:1m 作者: 分享 复制网址

Rust常见库使用示例。

标准库

命令行参数


  • 执行
$ cargo run abcdef
   Compiling test123 v0.1.0 (/Users/xiexianbin/workspace/code/github.com/xiexianbin/rust-study/test123)
    Finished dev [unoptimized + debuginfo] target(s) in 0.62s
     Running `target/debug/test123 abcdef`
["target/debug/test123", "abcdef"], args[0]: "target/debug/test123"
  • 结合 struct 的示例

读文件

use std::fs;

fn main() {
    let c = fs::read_to_string("./main.rs").expect("file main.rs not found.");

    println!("{:?}", c);
}

读环境变量

use std::env;

let name = env::var("ENV_NAME").is_err();

sleep

use std::thread;
use std::time::Duration;

// sleep 1 second
thread::sleep(Duration::from_secs(1));
Home Archives Categories Tags Statistics
本文总阅读量 次 本站总访问量 次 本站总访客数