refactor(examples): migrate to a package-per-example layout - #1937
Merged
gold-silver-copper merged 2 commits intoJun 22, 2026
Merged
Conversation
Convert the 54 flat `examples/*.rs` files (built as cargo examples of the root `rig` crate against one shared, large dev-dependencies block) into a package per example under `examples/<name>/`, ratatui-style. - Each example is its own `publish = false` workspace member with its own Cargo.toml declaring only the dependencies it uses, inheriting workspace lints (`[lints] workspace = true`). - Per-example `required-features` are now enabled directly on the `rig` path dependency (derive, pdf, rmcp, discord-bot, reqwest-middleware, image). - `examples/*` added to workspace members; `examples/documents` (PDF data) and `examples/otel` (Docker/config infra) excluded as non-packages. - Root crate gets `autoexamples = false`; all `[[example]]` blocks removed. - The `rmcp` example package is named `rmcp_example` to avoid colliding with the `rmcp` crate it depends on (directory stays `examples/rmcp`). - Added `examples/README.md` index with `cargo run -p <name>` instructions. Run an example with `cargo run -p <name>` instead of `cargo run --example <name>`. Note: `gemini_nanobanana_image_generation` previously only built under CI's `--all-features`; it now declares the `image` feature it needs. Root `[dev-dependencies]` are left intact since the `tests/` suite depends on them.
Add `rig = { path = ".", version = "0.39.0" }` to [workspace.dependencies]
(the facade is the workspace-root package) and have each example use
`rig.workspace = true` instead of an explicit path dependency. Examples that
need features add them at the use site, e.g. `rig = { workspace = true,
features = ["derive"] }`. Mirrors ratatui's examples setup.
Merged
Closed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Inspired by @Atliac 's PR: #1912 . Thank you!
Migrates the 54 flat
examples/*.rsfiles — previously compiled as cargo examples of the rootrigcrate, all sharing one large[dev-dependencies]block — into a package per example underexamples/<name>/, in the style of ratatui'sexamples/. Kept flat (one package per example dir); noapps//state//vhs/sub-grouping.What changed
examples/<name>/Cargo.toml+src/main.rs),publish = false, inheriting workspace lints via[lints] workspace = true.[workspace.dependencies]), instead of every example seeing the whole shared dev-deps surface.rigdependency. Examples that previously neededrequired-featuresnow enable those features directly on theirrigpath dep:derive,pdf,rmcp,discord-bot,reqwest-middleware, andimage.examples/*added tomembers;examples/documents(PDF data used bypdf_agent) andexamples/otel(Dockerfile/config infra) areexcluded as non-packages. Root crate getsautoexamples = falseand all[[example]]blocks are removed.rmcpexample package is namedrmcp_exampleto avoid a cargo name collision with thermcpcrate it depends on (directory staysexamples/rmcp).examples/README.mdindexing every example withcargo run -p <name>instructions.Run an example with
cargo run -p <name>(wascargo run --example <name>).Notes / decisions
gemini_nanobanana_image_generationpreviously compiled only under CI's--all-features(feature unification suppliedimage); it now declares theimagefeature it genuinely needs, so it builds standalone.examples/documents/is kept in place;pdf_agentresolves it relative to the workspace root (current_dir()/examples/documents), which holds when running viacargo run -p pdf_agentfrom the repo root.[dev-dependencies]left intact — thetests/suite (provider cassette tests,tests/integrations/*, testcontainers, httpmock, sqlx, mongodb, …) depends on them; only the[[example]]target declarations were removed.examples/*are now workspace members,cargo build/clippy --workspacecompiles all examples. Per-example builds (cargo run -p <name>) are now much lighter, since each pulls only its own deps.Verification
cargo build --workspace: green.cargo build -p <name>for all 54): all pass — confirms no example relies on feature unification from a sibling.cargo clippy -p <each example> --all-targets: clean (workspace deny-lints apply).cargo fmt --check: clean.