Changes for the 2022 rewrite / reorginzation / expansion:
- All examples updated to Rust edition 2021, and the latest stable versions of the crates.
- All example code moved to actual
.rs
files. All examples are runnable inside the project viacargo run --example
, and 100% of the examples are also run viacargo test
. This makes it easier for users to run the examples that are incompatible with the Rust Playground because they interact with the filesystem, or a database, etc.. Modifying and running the examples on the command line shall be encouraged. - As a consequence of the above, elimination of the
skeptic
crate to test code within the Markdown files. Source code for the examples is brought in by the{{#include examples/foobar.rs}}
Markdown directive. - The code is organized as a series of workspaces. This also avoids the
problem with the
skeptic
based test system which would sometimes link in the incorrect version of a crate for a particular codebase. All the workspaces share the same target directory, which should reduce compilation times. - No hiding of details. All code presented as full and complete. The documentation should explain any details needed to understand the example.
- Remove use of
error-chain
crate. This has been replaced with the simpler use ofResult<(), Box<dyn Error>>
or similar in the examples. There will be an extended section on usinganyhow
andthiserror
as well. See also: https://nick.groenen.me/posts/rust-error-handling/ - As a consequence of the above, updating to the current stable versions
of crates is possible with a couple commands from
cargo-edit
andcargo-upgrades
. When using the "nightly" channel of the Rust toolchain, runningcargo update -Z unstable-options --breaking
(modifies theCargo.lock
) and then runningcargo test
should identify any API changes. After everything works again, runningcargo upgrade -Z unstable-options --breaking
can then be used to insert the updated crate versions into theCargo.toml
files. This all should be done frequently, so that the Cookbook shows examples that are correct for the current stable versions of crates.