Skip to content

refactor(examples): migrate to a package-per-example layout - #1937

Merged
gold-silver-copper merged 2 commits into
0xPlaygrounds:mainfrom
gold-silver-copper:refactor/examples-package-per-example
Jun 22, 2026
Merged

refactor(examples): migrate to a package-per-example layout#1937
gold-silver-copper merged 2 commits into
0xPlaygrounds:mainfrom
gold-silver-copper:refactor/examples-package-per-example

Conversation

@gold-silver-copper

@gold-silver-copper gold-silver-copper commented Jun 22, 2026

Copy link
Copy Markdown
Contributor

Summary

Inspired by @Atliac 's PR: #1912 . Thank you!

Migrates the 54 flat examples/*.rs files — previously compiled as cargo examples of the root rig crate, all sharing one large [dev-dependencies] block — into a package per example under examples/<name>/, in the style of ratatui's examples/. Kept flat (one package per example dir); no apps//state//vhs/ sub-grouping.

What changed

  • Each example is now its own package (examples/<name>/Cargo.toml + src/main.rs), publish = false, inheriting workspace lints via [lints] workspace = true.
  • Minimal per-example dependencies. Each manifest declares only the third-party crates that example actually uses (pulled from [workspace.dependencies]), instead of every example seeing the whole shared dev-deps surface.
  • Feature gating moved onto the rig dependency. Examples that previously needed required-features now enable those features directly on their rig path dep: derive, pdf, rmcp, discord-bot, reqwest-middleware, and image.
  • Workspace wiring. examples/* added to members; examples/documents (PDF data used by pdf_agent) and examples/otel (Dockerfile/config infra) are excluded as non-packages. Root crate gets autoexamples = false and all [[example]] blocks are removed.
  • Naming. Example names/directories are preserved, except the rmcp example package is named rmcp_example to avoid a cargo name collision with the rmcp crate it depends on (directory stays examples/rmcp).
  • Added examples/README.md indexing every example with cargo run -p <name> instructions.

Run an example with cargo run -p <name> (was cargo run --example <name>).

Notes / decisions

  • gemini_nanobanana_image_generation previously compiled only under CI's --all-features (feature unification supplied image); it now declares the image feature it genuinely needs, so it builds standalone.
  • Data dir examples/documents/ is kept in place; pdf_agent resolves it relative to the workspace root (current_dir()/examples/documents), which holds when running via cargo run -p pdf_agent from the repo root.
  • Root [dev-dependencies] left intact — the tests/ suite (provider cassette tests, tests/integrations/*, testcontainers, httpmock, sqlx, mongodb, …) depends on them; only the [[example]] target declarations were removed.
  • Build-time tradeoff: since examples/* are now workspace members, cargo build/clippy --workspace compiles 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.
  • Every example built in isolation (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.

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.
@gold-silver-copper
gold-silver-copper added this pull request to the merge queue Jun 22, 2026
Merged via the queue into 0xPlaygrounds:main with commit 4346a50 Jun 22, 2026
5 checks passed
@github-actions github-actions Bot mentioned this pull request Jun 22, 2026
@github-actions github-actions Bot mentioned this pull request Jul 11, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant