我对 Rust 还不熟悉。我尝试使用 crate
复制步骤如下:
在我的
js_sys
,其中包含 Math::log
。按照 crate 网站告诉我的,我已经在 Cargo.toml
中包含了 js_sys = 0.3.48
,并在 main.rs
中使用 use js_sys::Math::log;
。然而,我收到了一个错误,提示 rust 找不到 crate。复制步骤如下:
[package]
name = "sim"
version = "0.1.0"
authors = ["Excluded for privacy"]
edition = "2018"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]
js_sys = "0.3.48"
rand = "0.8.3"
在我的
main.rs
文件的顶部// Luke Anglin and Tobi Solarin
use js_sys::Math::log;
use rand::prelude::*; // For the rng
const n: i32 = 1_000; // The number of trials
错误
error: no matching package named `js_sys` found
location searched: registry `https://github.com/rust-lang/crates.io-index`
perhaps you meant: js-sys
required by package `sim v0.1.0 (/Users/lukeanglin/Desktop/Probability/Project2/simulator/sim)`
use
时,我还在 cargo.toml 中将其更改为 js-sys,但它没有起作用。显然,在 toml 中必须使用破折号,但在 use 中不需要。对我来说很困惑! - user11391572