How to list all examples?

If I run cargo run --example, it will fail with a list of all possible examples:

$ cargo run --example 
error: "--example" takes one argument.
Available examples:
    blob
    collection
    database
    engine
    engine
    i64
    list
    map
    tutorial
    txn

However, I'd like to get a successful results of listing all possible examples.

It's further than just list all files under examples/ folder since there can be multiple workspace members. (And I'm actually curious about how the command above finds all examples even if I run in the workspace root path instead of the member crate root path.)

You can take engula/engula project as an example.

You can use the cargo metadata command to get a picture of your workspace's entire crate graph, including things like binaries, integration tests, and examples. Programmatically, you could use the cargo_metadata crate, using Metadata's workspace_members field to filter packages, then looking at each package's targets for things where target.kind.contains("example").

There's probably a simpler way from the command-line, but I've only ever done this sort of thing programmatically.

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.