Skip to content

Support examples with their own Cargo.toml files #15324

Open
@jbethune

Description

@jbethune

Problem

The official package layout says that there can be an examples folder in a cargo package. This examples folder currently supports

  1. examples/foo.rs standalone files
  2. examples/foo/main.rs files in subfolders with supporting modules

I can compile and run these examples with

cargo run --example foo

However, some examples require a more complex setup. The examples folder of the axum project contains many subfolders and each subfolder contains a cargo package with a Cargo.toml.

It would be nice if cargo run --example foo supported a third case:

  1. examples/foo/Cargo.toml should run the default binary from the cargo example package.

Proposed Solution

  1. Implement support for finding examples with Cargo.toml files inside the examples folder
  2. Easy solution: Automatically change into the directory of the examples crate and start a cargo run subprocess.

Notes

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-examplesArea: example targetsC-feature-requestCategory: proposal for a feature. Before PR, ping rust-lang/cargo if this is not `Feature accepted`S-triageStatus: This issue is waiting on initial triage.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions