Multi-file examples
Cargo has an examples
feature for showing people how to use your package.By putting individual files inside of the top-level examples
directory, youcan create multiple examples.
But what if your example is too big for a single file? Cargo supports addingsub-directories inside of examples
, and looks for a main.rs
inside ofthem to build the example. It looks like this:
my-package
└──src
└── lib.rs // code here
└──examples
└── simple-example.rs // a single-file example
└── complex-example
└── helper.rs
└── main.rs // a more complex example that also uses `helper` as a submodule