mac编译dbgen出错rand::rngs::OsRng

errorE0432: unresolved import `rand::rngs::OsRng`

--> /Users/lanyuan/.cargo/registry/src/index.crates.io-6f17d22bba15001f/dbgen-0.8.0/src/cli.rs:19:27

|

19 | rngs::{mock::StepRng, OsRng},

| ^^^^^ no `OsRng` in `rngs`

|

note: found an item that was configured out

--> /Users/lanyuan/.cargo/registry/src/index.crates.io-6f17d22bba15001f/rand-0.8.5/src/rngs/mod.rs:119:50

|

119 | #cfg(feature = "getrandom") pub use rand_core::OsRng;

| ^^^^^

= note: the item is gated behind the `getrandom` feature

errorE0432: unresolved import `rand::rngs::OsRng`

--> /Users/lanyuan/.cargo/registry/src/index.crates.io-6f17d22bba15001f/dbgen-0.8.0/src/schemagen_cli.rs:5:12

|

5 | use rand::{rngs::OsRng, seq::SliceRandom, Rng, RngCore, SeedableRng};

| ^^^^^^^^^^^ no `OsRng` in `rngs`

|

note: found an item that was configured out

--> /Users/lanyuan/.cargo/registry/src/index.crates.io-6f17d22bba15001f/rand-0.8.5/src/rngs/mod.rs:119:50

|

119 | #cfg(feature = "getrandom") pub use rand_core::OsRng;

| ^^^^^

= note: the item is gated behind the `getrandom` feature

分析:

网上和kimi提示添加依赖到Cargo.toml:

dependencies

rand = { version = "0.8", features = "getrandom" }

根据编译路径,找到/Users/lanyuan/.cargo/registry/src/index.crates.io-6f17d22bba15001f/dbgen-0.8.0,打开Cargo.toml,长这样:

dependencies.rand

version = "0.8.5"

default-features = false

修改false为true解决。

语法差别是rust 1.49 2018版本同rust 1.79的区别。

For more information about this error, try `rustc --explain E0432`.

error: could not compile `dbgen` (lib) due to 2 previous errors

error: failed to compile `dbgen v0.8.0`, intermediate artifacts can be found at `/var/folders/qn/sls3xhws4218snv410vq6x380000gn/T/cargo-installNSCX7t`.

相关推荐
PBitW4 分钟前
git 中容易遗忘的点 (二) ⚡⚡⚡
前端·git·面试
Hilaku12 分钟前
2026 年前端大洗牌:React 服务端到 Vite 的底层重构
前端·javascript·程序员
其美杰布-富贵-李24 分钟前
Spring Boot 依赖注入说明文档
java·spring boot·python
PBitW25 分钟前
git 中容易遗忘的点 (三) 🚀🚀🚀
前端·git·面试
名字还没想好☜27 分钟前
React setState 连续调用「丢更新」排查:批量更新与函数式更新
前端·javascript·react.js·react·usestate
tachibana229 分钟前
hot100 数组中的第K个最大元素(215)
java·数据结构·算法·leetcode
bitbrowser31 分钟前
Facebook 验证反复回到原页面,应该从哪里排查
运维·服务器·facebook
our_times33 分钟前
2026年Java开发者破局指南:Spring AI 2.0 与 Agent 开发实战
java·人工智能·spring
come1123442 分钟前
Vue 2 与 Vue 3 语法区别及使用技巧
前端·javascript·vue.js
腻害兔1 小时前
【若依项目-产品经理视角】RuoYi-Vue-Pro 源码拆解:ERP 企业资源模块,一个轻量级进销存的完整实现?
前端·javascript·vue.js·人工智能·前端框架·产品经理·ai编程