I've got code for an MSD radix sort which can optionally run multithreaded via rayon. I'd like to move that parallel sort out to its own crate. Then you don't take the rayon dependency if you don't want it.
The two sorts share the core function to partition an input slice into a bunch of buckets. That function would ordinarily be private. But if I want to use that function in the serial crate (mmm, cereal crate) and the parallel crate, keeping it private is tricky.
- Make it a public API in a third crate so it doesn't clutter up either of the main crates' APIs
- Make it a public API of the serial crate, with docs explaining it's only exposed out of necessity and you probably don't want it, but described enough you could use it in theory
- Make it a public API of the serial crate, but only document "here be dragons; this is exposed for other_crate_name to use"
- Duplicate the function in the parallel and serial crates so it's not a public API anywhere
Right now my top preference is a third crate, probably. Is one of the other options more idiomatic, e.g. is it a common/accepted wart to say "this thing is nominally public but really for one 'friend' crate", or to accept internal code duplication in this kind of situation? Is there some other, better approach? (Thanks!)