-
Notifications
You must be signed in to change notification settings - Fork 313
Move algorithms/randomness to crates #737
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Self review notes.
with: | ||
cache: 'true' | ||
cache: "true" | ||
toolchain: stable |
There was a problem hiding this comment.
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()); |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
let password: String = (0..PASSWORD_LEN) | ||
.map(|_| rng.sample(Alphanumeric) as char) | ||
.collect(); |
There was a problem hiding this comment.
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.
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`]. |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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" |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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
license = "MIT/Apache-2.0" | ||
license = "MIT OR Apache-2.0" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This format was incorrect
There was a problem hiding this comment.
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
[workspace.dependencies] | ||
rand = "0.9" | ||
rand_distr = "0.5" |
There was a problem hiding this comment.
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:
# 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 |
There was a problem hiding this comment.
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] |
There was a problem hiding this comment.
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.
6d9b545
to
0fd7036
Compare
There was a problem hiding this 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.
There was a problem hiding this comment.
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()); |
There was a problem hiding this comment.
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.
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`]. |
There was a problem hiding this comment.
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.
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
cargo xtask test all
https://docs.rs/tar/*/tar/struct.Entry.html
Things to do after submitting PR