Is it possible to build examples in binary crate?

It's probably a stupid question because binary crates aren't meant to provide any examples. I'm aware that it makes more sense to have examples in library crates only.

However I have some modules declared into the binary to which I'd like to provide examples so they can be ran independently.

So I tried adding examples to the root of the crate, however it doesn't seem to recognize the namespaces at all.

If the examples need to use parts of the crate itself, it will need to be a library. You can have it all though, a lib.rs for shared code, main.rs for your main binary (and/or as many bin/*.rs as you want), and then your examples.

Not really what I need unfortunately, but thanks anyway. I'll probably stick to examples in documentation.

I'm starting to think that it would be nice to have module scoped examples.

How are you expecting these modules to be run? AFAIK, you can't use binary-only crate as a dependency anyway.

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.