Skip to content

常用依赖

uuid

在 Cargo.toml 中添加以下依赖

bash
[dependencies]
uuid = { version = "1.4.0", features = ["serde", "v4"] }

使用:

rust
use uuid::Uuid;

// 生成 uuid
let id = Uuid::new_v4().to_string()

println!("{}", id);

log 日志

安装依赖:

bash
cargo add log

cargo add env_logger

使用:

rust
// 添加日志
env_logger::init_from_env(env_logger::Env::new().default_filter_or("info"));
// 打印 info 级别日志
log::info!("starting HTTP server at http://localhost:8080");

个人收集整理, MIT License