These are chat archives for rust-lang/rust

1st
Jul 2018
Fredrik Portström
@portstrom
Jul 01 2018 17:42 UTC
I think HashMap should have a function that is like entry but takes impl ToOwned<T> instead of T as the key. This would avoid unnecessary cloning when the key already exists in the collection. Is there such a proposal?
KillTheMule
@KillTheMule
Jul 01 2018 18:28 UTC
I'd need advice, please. I have some benchmarks in benches (I'm using criterion), and the use some common code, which really is specific to benchmarks and not needed somewhere else. Where can I put that code to import it into the benchmarks properly? I tried making benches/common.rs but there seems to be no way to use common; or something.
Dmitriy
@dpogretskiy
Jul 01 2018 19:21 UTC
did you try self::common?
if it's not work what is exactly the file structure
KillTheMule
@KillTheMule
Jul 01 2018 19:27 UTC
Yeah I did, that didn't work either. I have the benches directory containing the files integration.rs and card.rs. Both benchmarks run properly, but make use of a function conf that as of now is defined identically in both files.
Dmitriy
@dpogretskiy
Jul 01 2018 19:28 UTC
do you have mod.rs?
KillTheMule
@KillTheMule
Jul 01 2018 19:28 UTC
Hmm, hmm, no, I don't, I guess I should? I'll try!
Dmitriy
@dpogretskiy
Jul 01 2018 19:28 UTC
yeah, and you need to say there that you have mods in
mod integration; mod card; etc
KillTheMule
@KillTheMule
Jul 01 2018 19:31 UTC
Yeah I put mod integration; mod card; mod common in there, and put the function in benches/common.rs. But I can' use use self::common; in integration.rs, nor use benches::common;
Dmitriy
@dpogretskiy
Jul 01 2018 19:32 UTC
and if it's super::common?
super::benches::common
something like that
it's totally possible, you just need to figure out the way :)
KillTheMule
@KillTheMule
Jul 01 2018 19:33 UTC
Both didn't work, too :(
Dmitriy
@dpogretskiy
Jul 01 2018 19:34 UTC
we need to go deeper!
you have a file, say common.rs
KillTheMule
@KillTheMule
Jul 01 2018 19:35 UTC
Do I need to declar "benches" as an extern crate?
Dmitriy
@dpogretskiy
Jul 01 2018 19:35 UTC
oh, are benches a mod in main.rs?
or lib.rs
if you have something like card.rs
KillTheMule
@KillTheMule
Jul 01 2018 19:36 UTC
Neither, the benches directory lives on the same level as src
Dmitriy
@dpogretskiy
Jul 01 2018 19:36 UTC
and mod cards { your beches } in it, then it's cards::cards
then main.rs should say it has mod benches;
probably #[cfg(test)] mod benches
otherwise they are not part of the project
ever heard that rust module system is somewhat weird? :laughing:
you can check out this
i have some modules there
main.rs has to declare all modules on it's level
KillTheMule
@KillTheMule
Jul 01 2018 19:40 UTC
Yeah thanks, my module structure works, it's the benchmarks that behave somewhat peculiar
But I think I'll try to copy the structure that Criterion itself uses for its benchmarks, seems sane and I assume it works
Dmitriy
@dpogretskiy
Jul 01 2018 19:41 UTC
well, yeah i can't tell any more, not knowing what you mod structure is :)
maybe benchmarks don't work like this
KillTheMule
@KillTheMule
Jul 01 2018 19:42 UTC
You could have a look here: https://github.com/KillTheMule/nvimpam
Dmitriy
@dpogretskiy
Jul 01 2018 19:42 UTC
i actually never tried :)
KillTheMule
@KillTheMule
Jul 01 2018 19:42 UTC
Yeah I think benchmarks are special :)
Dmitriy
@dpogretskiy
Jul 01 2018 19:44 UTC
i used outside code from benchmarks, but it was always in same file
reasonably :)
KillTheMule
@KillTheMule
Jul 01 2018 19:45 UTC
Oookkkk I found the problem, sigh...
I was saving mod.rs in the wrong directory, so of course it could not be found, no matter the invocation...
Thanks for helping though, sometimes someone listening is all it takes :D
KillTheMule
@KillTheMule
Jul 01 2018 19:51 UTC
Just in case, here is the (working) result, and the relevant commit is [this]. Thanks again!
Dmitriy
@dpogretskiy
Jul 01 2018 20:07 UTC
@KillTheMule oh, it's not even in src :)
good you've found it out