Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Copy&pasted examples fail due to auto-added fn main(){} #829

Open
eugenesvk opened this issue Dec 6, 2024 · 0 comments
Open

Copy&pasted examples fail due to auto-added fn main(){} #829

eugenesvk opened this issue Dec 6, 2024 · 0 comments

Comments

@eugenesvk
Copy link

When trying to follow code examples from Getting Started a user could be enticed by the copy&paste button in Step 2 - Add Benchmark to simply paste the code to his local file, but that sneaky button adds fn main() {, which blocks he invokation of the benchmark macro main function, so the benches would never run

#![allow(unused)]
fn main() {
use criterion::{black_box, criterion_group, criterion_main, Criterion};
use mycrate::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);
}

You should either

  • remove the copy&paste button so that users would copy&paste manually without having that blocking main added
  • configure docs to generate a button that doesn't copy the hidden text
  • Or even better: have self-contained examples that work, then the user would simply download the files and don't have to waste time trying to figure out why the guide doesn't work
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant