7 releases (4 breaking)

0.5.0 Mar 10, 2023
0.4.0 Jan 16, 2023
0.3.0 Dec 26, 2022
0.2.1 Nov 13, 2022
0.1.1 Sep 30, 2022

#398 in Cargo plugins

Download history 92/week @ 2024-07-19 12/week @ 2024-07-26 19/week @ 2024-08-02 1/week @ 2024-08-09 25/week @ 2024-08-16 6/week @ 2024-08-23 6/week @ 2024-08-30 2/week @ 2024-09-06 8/week @ 2024-09-13 16/week @ 2024-09-20 11/week @ 2024-09-27 21/week @ 2024-10-04 7/week @ 2024-10-11 9/week @ 2024-10-18 71/week @ 2024-10-25 16/week @ 2024-11-01

104 downloads per month

MIT/Apache

12KB
171 lines

cargo-examples

cargo-examples is a cargo subcommand that lets you run all examples in any locally cloned crate.

My main motivation for this tool is that when checking out a library or binary, I want to run all the examples so I can quickly grasp the inner workings of a crate interactively.

This tool supports running examples the same way cargo run --example <name> does, meaning it can run single files from examples directory, multi-file examples in examples directory and manifest-based example specified in projects Cargo.toml.

In addition to this cargo-examples allows you to run subproject examples from examples directory, meaning subproject directories with Cargo.toml that sit in examples directory, this can be seen in many projects across Rust ecosystem which have more involved examples, cargo cannot run this out-of-the box with cargo run --example <name>.

Single file example
<project>/examples/foo.rs

Multi file example
<project>/examples/bar/main.rs

Subproject example
<project>/examples/baz/Cargo.toml

Manifest based example [[example]] in Cargo.toml

Installing

You can install this with cargo:

cargo install cargo-examples

Usage

Clone your favorite crate, cd into the repo and run cargo examples

By default, cargo examples will run all the examples in a crate in order.

There are cli options that you can use to modify how the examples are ran:

Cargo subcommand to run all examples for any locally cloned crate
USAGE:
    cargo examples [OPTIONS] [-- <CARGO_ARGS>...]
ARGUMENTS:
    [CARGO_ARGS]...  Pass these arguments along to cargo when running
OPTIONS:
        --manifest-path <FILE>  Path to Cargo.toml
    -l, --list                  List *all* examples and print them out before running any
    -p, --print                 Print example name before running
    -f, --from <EXAMPLE>        Run example starting with <EXAMPLE>
    -n, --no-run                Do not run any examples, useful when combined with `--list`, or `--from` + `--print`
    -s, --skip <EXAMPLE>        Skip <EXAMPLE> when running. (--skip=example1,example2)
    -F, --features <FEATURES>   Run examples with <FEATURES> enabled. (--features=feature1,feature2)
    -h, --help                  Print help
    -V, --version               Print version

Dependencies

~1.6–2.4MB
~45K SLoC