What is the best way to prepare a crate?

I have written a small library, which is designed to use with egui, or any other UI framework.

Now my project looks like:

src/lib.rs            // the library itself
examples/main.rs      // app, which demonstrates the features
examples/helper.rs    // helper class for the demo
examples/demo1.rs     // feature 1 demo
examples/demo2.rs     // feature 2 demo

It looks okay in GutHub, but not if I want to make a crate from it: the demo code is 20x as big as the library itself.

FIrst of all, I want to split the project, there should be a separate repository for the lib and another one the demos. Especially, I want to make the demo publish on web (whit egui), and I will use eframe_template, which is also too big to include it with the lib.

The final solution would be upload the lib as a crate, and it should have a link to the demo repository, which is using the crate.

But I don't want to create a crate right now, probably there will be some changes, which will come up using it, I mean during writing demos. So, my question is: how can I use a library outside a project, if it was a crate? The best solution would be upload it to crates.io, but as a private one. Is there such on crates.io?

Maybe, I'm wrong, and the original directory structure is okay, if a program uses my crate, it will use only lib.rs and not the examples?

As general advice, two features might be helpful to you:

For your questions:

I hope I'm understanding correctly, but this sounds like a case for a path dependency (but you won't be able to publish crates with path dependencies).

There's no feature for private crates on crate.io.

It should work when using the exclude feature. Your structure looks correct.

1 Like

You can upload it to crates.io as-is. The examples will be uploaded too, but they wont actually be accessible to people using it from crates.io.


cargo install --examples allows installing examples of packages published on crates.io.

1 Like