nvzqz / divan

Fast and simple benchmarking for Rust projects
https://nikolaivazquez.com/blog/divan/
Apache License 2.0
849 stars 24 forks source link

Allow bench_refs() and bench_local_refs() to capture input lifetimes #54

Open neocturne opened 2 months ago

neocturne commented 2 months ago

This allows benchmarks using bench_refs() and bench_local_refs() to capture the input lifetimes, as was already suggested by TODO comments in the code.

By naming the input lifetime, the output type O is allowed to capture this lifetime. The I: 'i condition for &'i mut I must be made explicit now with named 'i, or the code won't compile.

First commit adds tests that don't compile, second commit makes them compile.

neocturne commented 1 month ago

Any suggestions for a good example? In my project I'm using it for benchmarking a parser that creates a token stream/tree which references the input, but that seems too complex for an example (and it uses a separate parser crate). I guess I could do something simple like collecting the result of str::matches() in a Vec that gets returned?