Skip to content

Commit 689b4e2

Browse files
committed
update original
1 parent 5acb819 commit 689b4e2

22 files changed

Lines changed: 296 additions & 162 deletions

File tree

rust-cookbook/.github/workflows/mdbook-test.yml

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ jobs:
2727
- name: Test Results
2828
if: always()
2929
run: |
30-
if [ ${{ steps.cargo_test.outcome }} == 'success' ]; then
30+
if [ "${{ steps.cargo_test.outcome }}" == "success" ]; then
3131
echo "✅ All tests passed!"
3232
else
3333
echo "❌ Some tests failed. Check the logs above for details."
@@ -40,11 +40,13 @@ jobs:
4040
steps:
4141
- uses: actions/checkout@v5
4242
- uses: actions-rust-lang/setup-rust-toolchain@v1
43-
- run: cargo check --workspace
43+
- name: cargo check
44+
id: cargo_check
45+
run: cargo check --workspace
4446
- name: Check Results
4547
if: always()
4648
run: |
47-
if [ ${{ steps.cargo_check.outcome }} == 'success' ]; then
49+
if [ "${{ steps.cargo_check.outcome }}" == "success" ]; then
4850
echo "✅ Workspace check passed!"
4951
else
5052
echo "❌ Workspace check failed. Check the logs above for details."

rust-cookbook/CONTRIBUTING.md

Lines changed: 24 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,12 @@ To run the cookbook test suite:
4444
cargo test
4545
```
4646

47+
To run only the skeptic tests (useful when working on examples):
48+
49+
```
50+
cargo test --test skeptic
51+
```
52+
4753
### xtask
4854

4955
To simplify common tasks like testing, building the book, and running linters.
@@ -60,6 +66,12 @@ cargo install mdbook@0.4.43 lychee@0.17.0
6066
cargo xtask test all
6167
```
6268

69+
- To run only the skeptic tests:
70+
71+
```bash
72+
cargo test --test skeptic
73+
```
74+
6375
- To build the book locally:
6476

6577
```bash
@@ -75,28 +87,24 @@ run on the continuous integration server. These linters should be run locally
7587
before submitting a pull request to ensure there are no dead links or spelling
7688
errors made.
7789

78-
To install the link checker, review the documentation for [python] to install
79-
python 3.6 and pip3. Installing link-checker once the dependencies are met
80-
is done with pip3.
90+
To install the link checker, use Cargo:
8191

82-
```
83-
[sudo] pip3 install link-checker==0.1.0
92+
```bash
93+
cargo install lychee@0.17.0
8494
```
8595

86-
Alternatively, add the user install directory (probably `~/.local/bin`) to
87-
your PATH variable and install link-checker for your user.
96+
Checking the links of the book locally can be done with the xtask tool.
97+
First, ensure the book is built with mdBook.
8898

89-
```
90-
pip3 install --user link-checker==0.1.0
99+
```bash
100+
cargo xtask book
101+
cargo xtask test link
91102
```
92103

93-
Checking the links of the book locally first requires the book to be built
94-
with mdBook. From the root directory of the cookbook, the following commands
95-
run the link checker.
104+
Alternatively, you can run lychee directly to check all files in the repository:
96105

97-
```
98-
mdbook build
99-
link-checker ./book
106+
```bash
107+
lychee --base . --config ./ci/lychee.toml .
100108
```
101109

102110
The aspell binary provides spell checking. Apt packages provide installation
@@ -132,7 +140,7 @@ Pressing `a` or `l` will not add the word to the custom dictionary.
132140
If there are no errors, it will just print the local Aspell version and exit.
133141

134142
[mdbook]: https://github.com/rust-lang-nursery/mdBook
135-
[python]: https://packaging.python.org/tutorials/installing-packages/#install-pip-setuptools-and-wheel
143+
[lychee]: https://github.com/lycheeverse/lychee
136144
[skeptic]: https://github.com/brson/rust-skeptic
137145

138146

rust-cookbook/Cargo.toml

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
[workspace]
2-
members = ["crates/algorithms/*", "crates/web", "xtask"]
2+
members = ["crates/algorithms/*", "crates/development_tools/debugging/tracing", "crates/web", "xtask"]
33

44
[workspace.package]
55
edition = "2024"
@@ -23,6 +23,8 @@ default = []
2323
[workspace.dependencies]
2424
rand = "0.9"
2525
rand_distr = "0.5"
26+
tracing = "0.1"
27+
tracing-subscriber = "0.3"
2628

2729
# NOTE: These dependencies add dependencies to the rust playground (play.rust-lang.org).
2830
# Be wary removing or changing these without considering this fact.
@@ -77,6 +79,8 @@ thiserror = "2"
7779
threadpool = "1.8"
7880
tokio = { version = "1", features = ["full"] }
7981
toml = "0.8"
82+
tracing = "0.1"
83+
tracing-subscriber = "0.3"
8084
unicode-segmentation = "1.2.1"
8185
url = "2.5"
8286
walkdir = "2.5"

rust-cookbook/build.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,10 @@ const REMOVED_TESTS: &[&str] = &[
55
"./src/web/clients/api/rate-limited.md",
66
];
77

8-
const REMOVED_PREFIXES: &[&str] = &["./src/algorithms/randomness/"];
8+
const REMOVED_PREFIXES: &[&str] = &[
9+
"./src/algorithms/randomness/",
10+
"./src/development_tools/debugging/tracing/",
11+
];
912

1013
fn main() {
1114
let paths = WalkDir::new("./src/")
Lines changed: 24 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,32 @@
1-
use rand::Rng;
2-
use rand_distr::Alphanumeric;
1+
use rand::{distr::Alphanumeric, Rng};
32

43
fn main() {
4+
let password = generate_password();
5+
println!("{password}");
6+
}
7+
8+
fn generate_password() -> String {
59
const PASSWORD_LEN: usize = 30;
610
let mut rng = rand::rng();
711

8-
let password: String = (0..PASSWORD_LEN)
12+
(0..PASSWORD_LEN)
913
.map(|_| rng.sample(Alphanumeric) as char)
10-
.collect();
14+
.collect()
15+
}
1116

12-
println!("{password}");
17+
#[cfg(test)]
18+
mod tests {
19+
use super::*;
20+
21+
#[test]
22+
fn test_password_length() {
23+
let password = generate_password();
24+
assert_eq!(password.len(), 30);
25+
}
26+
27+
#[test]
28+
fn test_password_is_alphanumeric() {
29+
let password = generate_password();
30+
assert!(password.chars().all(|c| c.is_alphanumeric()));
31+
}
1332
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
[package]
2+
name = "tracing-console"
3+
version.workspace = true
4+
authors.workspace = true
5+
edition.workspace = true
6+
license.workspace = true
7+
publish.workspace = true
8+
9+
[dependencies]
10+
tracing.workspace = true
11+
tracing-subscriber.workspace = true
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
use tracing::{debug, error, info, trace, warn};
2+
3+
fn main() {
4+
tracing_subscriber::fmt::init();
5+
6+
error!("This is an error!");
7+
warn!("This is a warning.");
8+
info!("This is an informational message.");
9+
10+
// with the default configuration, debug! and trace! messages are not shown
11+
debug!("This is a debug message.");
12+
trace!("This is a trace message.");
13+
}
14+
15+
#[test]
16+
fn test_main() {
17+
main();
18+
}

rust-cookbook/crates/web/src/lib.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
mod broken;
2-
mod paginated;
3-
mod links;
4-
mod wiki;
1+
pub mod broken;
2+
pub mod paginated;
3+
pub mod links;
4+
pub mod wiki;
55

66
#[cfg(test)]
77
mod tests {

rust-cookbook/crates/web/src/wiki.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ use std::borrow::Cow;
33
use std::collections::HashSet;
44
use std::sync::LazyLock;
55

6-
pub fn extract_links(content: &str) -> HashSet<Cow<str>> {
6+
pub fn extract_links(content: &str) -> HashSet<Cow<'_, str>> {
77
static WIKI_REGEX: LazyLock<Regex> = LazyLock::new(|| Regex::new(
88
r"(?x)
99
\[\[(?P<internal>[^\[\]|]*)[^\[\]]*\]\] # internal links

rust-cookbook/src/SUMMARY.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
[Table of Contents](intro.md)
44
[About](about.md)
5+
56
- [Algorithms](algorithms.md)
67
- [Generate Random Values](algorithms/randomness.md)
78
- [Sort a Vector](algorithms/sorting.md)
@@ -28,6 +29,7 @@
2829
- [Debugging](development_tools/debugging.md)
2930
- [Log Messages](development_tools/debugging/log.md)
3031
- [Configure Logging](development_tools/debugging/config_log.md)
32+
- [Tracing Messages](development_tools/debugging/tracing.md)
3133
- [Versioning](development_tools/versioning.md)
3234
- [Build Time Tooling](development_tools/build_tools.md)
3335
- [Encoding](encoding.md)

0 commit comments

Comments
 (0)