Skip to content

Conversation

joshka
Copy link
Contributor

@joshka joshka commented Oct 2, 2025

This takes a slightly different approach to the way that the web crate works by moving all rust code to proper rust files and checking if the code compiles in CI.

Related to but does not completely fix #711


Things to check before submitting a PR

  • the tests are passing locally with cargo xtask test all
    • existing tests are broken
  • commits are squashed into one and rebased to latest master
  • PR contains correct "fixes #ISSUE_ID" clause to autoclose the issue on PR merge
    • if issue does not exist consider creating it or remove the clause
  • non rendered items are in sorted order (links, reference, identifiers, Cargo.toml)
  • links to docs.rs have wildcard version https://docs.rs/tar/*/tar/struct.Entry.html
    • latest instead
  • example has standard error handling
  • code identifiers in description are in hyperlinked backticks
[`Entry::unpack`]: https://docs.rs/tar/*/tar/struct.Entry.html#method.unpack

Things to do after submitting PR

  • check if CI is happy with your PR

Copy link
Contributor Author

@joshka joshka left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Self review notes.

Comment on lines 18 to 20
with:
cache: 'true'
cache: "true"
toolchain: stable
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This config is actually unnecessary as these are the default values


let password: String = (0..PASSWORD_LEN)
.map(|_| {
let idx = rng.random_range(0..CHARSET.len());
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed for rand 0.9 (gen_range -> random_range).

Moving away from skeptic here highlights deprecated code like this easily with standard tooling

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Praise: isolating our dependencies makes them much more deterministic.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note these files are in src/bin/. An alternative would be to put these in tests/ and have them actually run when running tests. This would require adding #[test] to each main function. I'm ambivalent as to which option is better with a slight preference for src/bin, but if running each example to ensure that it doesn't error when run has a higher precedence than I've assumed then tests/ with #[test] might be more convenient.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Praise: This makes the recipes and tests synchronized and there's no extra boiler plate

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is probably the main comment that I wanted feedback on. Do you want to run the code as part of the build, or is confirming that the code compiles enough?

The old rust adage of if it compiles it's correct is probably good enough for most things that would appear in the cookbook, but it could be reasonable to instead just write normal unit tests that show both the code and the expected output of things like this. I.e. instead of println!("...") in a main() function, we'd have have a test with an assertion that shows what's expected. This change would be useful for those that understand testing well, but it's a fairly significant difference to the way things are currently.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

for web I wrote explicit tests, but they don't run on ci. There has to be a mix of things that run and things that don't we aren't going to get postgres deployed. I'd like some testing, optionally added.

Comment on lines +8 to +10
let password: String = (0..PASSWORD_LEN)
.map(|_| rng.sample(Alphanumeric) as char)
.collect();
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The example from where this was copied was not using Alphanumeric, but the text said it was. Fixed this in this change.

Comment on lines -5 to +6
Randomly generates a string of given length ASCII characters with custom
user-defined bytestring, with [`gen_range`].
Randomly generates a string of given length ASCII characters with custom user-defined bytestring,
with [`random_range`].
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In general, I've rewrapped markdown at 100 chars to make it easier to read when editing. I'd recommend choosing a value (likely 100) and adding a markdownlint config file for this.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd accept a lint for it, I know the feeling about wanting to wrap lines.

members = ["crates/algorithms/*", "crates/web"]

[workspace.package]
edition = "2024"
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Going with the latest edition here for the new code. Thoughts / problems?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fingers crossed. I think its only an issue with skeptic

Comment on lines -6 to +16
license = "MIT/Apache-2.0"
license = "MIT OR Apache-2.0"
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This format was incorrect

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Praise: Thank you for fixing that

Comment on lines +23 to +25
[workspace.dependencies]
rand = "0.9"
rand_distr = "0.5"
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These won't yet affect the playground, but could reasonably easily by modifying the following code to include workspace deps:

https://github.com/rust-lang/rust-playground/blob/f8d7de52a3c139a0df4fe116bbbff19c30668c99/top-crates/src/lib.rs#L134-L161

Comment on lines +27 to +29
# NOTE: These dependencies add dependencies to the rust playground (play.rust-lang.org).
# Be wary removing or changing these without considering this fact.
# See https://github.com/rust-lang/rust-playground/blob/f8d7de52a3c139a0df4fe116bbbff19c30668c99/top-crates/src/lib.rs#L134-L161
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added this as it's tempting to remove the deps from here as they are not needed (rand / rand-distr are no longer included in the generated skeptic tests).

# NOTE: These dependencies add dependencies to the rust playground (play.rust-lang.org).
# Be wary removing or changing these without considering this fact.
# See https://github.com/rust-lang/rust-playground/blob/f8d7de52a3c139a0df4fe116bbbff19c30668c99/top-crates/src/lib.rs#L134-L161
[dependencies]
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Re-sorted this section correctly

This takes a slightly different approach to the way that the web crate
works by moving all rust code to proper rust files and checking if the
code compiles in CI.
@joshka joshka force-pushed the randomness-to-crate branch from 6d9b545 to 0fd7036 Compare October 2, 2025 22:54
@joshka joshka mentioned this pull request Oct 2, 2025
8 tasks
Copy link
Contributor

@AndyGauge AndyGauge left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I will see about not making ci required so we can make changes.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Praise: This makes the recipes and tests synchronized and there's no extra boiler plate


let password: String = (0..PASSWORD_LEN)
.map(|_| {
let idx = rng.random_range(0..CHARSET.len());
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Praise: isolating our dependencies makes them much more deterministic.

Comment on lines -5 to +6
Randomly generates a string of given length ASCII characters with custom
user-defined bytestring, with [`gen_range`].
Randomly generates a string of given length ASCII characters with custom user-defined bytestring,
with [`random_range`].
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd accept a lint for it, I know the feeling about wanting to wrap lines.

@AndyGauge AndyGauge merged commit 94c065e into rust-lang-nursery:master Oct 7, 2025
1 of 3 checks passed
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.

Move examples to rust projects (remove skeptic)
2 participants