ITADN

Getting Started code doesn't compile

#868Openbrasswood 创建于 2025-05-30
B
brasswoodcommented
I am completely new to this library. I followed the instructions at https://bheisler.github.io/criterion.rs/book/getting_started.html, using `criterion-tutorial` as my project name. Here is my directory structure: ```bash $ tree -I target criterion-tutorial criterion-tutorial ├── benches │   └── my_benchmark.rs ├── Cargo.lock ├── Cargo.toml └── src └── lib.rs ``` `src/lib.rs`: ```rust #[inline] fn fibonacci(n: u64) -> u64 { match n { 0 => 1, 1 => 1, n => fibonacci(n-1) + fibonacci(n-2), } } ``` `benches/my_benchmark.rs`: ```rust use criterion::{black_box, criterion_group, criterion_main, Criterion}; use criterion_tutorial::fibonacci; pub fn criterion_benchmark(c: &mut Criterion) { c.bench_function("fib 20", |b| b.iter(|| fibonacci(black_box(20)))); } criterion_group!(benches, criterion_benchmark); criterion_main!(benches); ``` Result: ```bash $ cargo bench Compiling criterion-tutorial v0.1.0 (criterion-tutorial) warning: function `fibonacci` is never used --> src/lib.rs:2:4 | 2 | fn fibonacci(n: u64) -> u64 { | ^^^^^^^^^ | = note: `#[warn(dead_code)]` on by default warning: `criterion-tutorial` (lib) generated 1 warning error[E0603]: function `fibonacci` is private --> benches/my_benchmark.rs:2:25 | 2 | use criterion_tutorial::fibonacci; | ^^^^^^^^^ private function | note: the function `fibonacci` is defined here --> criterion-tutorial/src/lib.rs:2:1 | 2 | fn fibonacci(n: u64) -> u64 { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ For more information about this error, try `rustc --explain E0603`. error: could not compile `criterion-tutorial` (bench "my_benchmark") due to 1 previous error warning: build failed, waiting for other jobs to finish... warning: `criterion-tutorial` (lib test) generated 1 warning (1 duplicate) ``` Making `fibonacci` pub fixed this. I apologize if I'm being pedantic but I just want to make sure: Is this a documentation typo or am I actually doing something wrong? It would make sense if criterion is supposed to be able to access private functions (if that's even possible), which is why I'm not certain.
1 条评论