mirror of
https://github.com/SergioBenitez/Rocket.git
synced 2026-02-06 10:48:05 +00:00
Update pastebin example to avoid new gen reserved keyword; couple of typo fixes (#2975)
Pastebin example uses now deprecated `rand::gen()` which was changed due to the reserved `gen` keyword in Rust 2024 edition. Rather than changing dependencies or updating the guide to specify an older edition, I've updated to use `gen_range` (should be best practice to avoid an infinitesimal bias anyway). This should work with any edition. Also fixed typos I noticed in the CONTRIBUTING doc. --------- Co-authored-by: Daniel Welsh <danielw2000@gmail.com> Co-authored-by: Matthew Pomes <matthew.pomes@pm.me>
This commit is contained in:
parent
0f73a60cc0
commit
3a54d079ae
@ -30,7 +30,7 @@ code you contribute must be:
|
||||
|
||||
* **Commented:** Complex or subtle functionality must be properly commented.
|
||||
* **Documented:** Public items must have doc comments with examples.
|
||||
* **Styled:** Your code must folow the [Code Style Conventions].
|
||||
* **Styled:** Your code must follow the [Code Style Conventions].
|
||||
* **Simple:** Your code should accomplish its task as simply and
|
||||
idiomatically as possible.
|
||||
* **Tested:** You must write (and pass) convincing [tests](#testing) for all
|
||||
@ -68,7 +68,7 @@ If you spot an open issue that you'd like to resolve:
|
||||
4. **Wait for a review, iterate, and polish.**
|
||||
|
||||
If a review doesn't come in a few days, feel free to ping a maintainer.
|
||||
Once somene reviews your PR, integrate their feedback. If the PR solves the
|
||||
Once someone reviews your PR, integrate their feedback. If the PR solves the
|
||||
issue (which it should because you have passing tests) and fits the project
|
||||
(which it should since you sought feedback _before_ submitting), it will be
|
||||
_conditionally_ approved pending final polish: documentation (rustdocs,
|
||||
|
||||
@ -62,7 +62,7 @@ parking_lot = "0.12"
|
||||
ubyte = {version = "0.10.2", features = ["serde"] }
|
||||
serde = { version = "1.0", features = ["derive"] }
|
||||
figment = { version = "0.10.17", features = ["toml", "env"] }
|
||||
rand = "0.8"
|
||||
rand = "0.9"
|
||||
either = "1"
|
||||
pin-project-lite = "0.2"
|
||||
indexmap = { version = "2", features = ["serde"] }
|
||||
|
||||
@ -182,9 +182,9 @@ Before we continue, we'll need to make a few design decisions.
|
||||
const BASE62: &[u8] = b"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";
|
||||
|
||||
let mut id = String::with_capacity(size);
|
||||
let mut rng = rand::thread_rng();
|
||||
let mut rng = rand::rng();
|
||||
for _ in 0..size {
|
||||
id.push(BASE62[rng.gen::<usize>() % 62] as char);
|
||||
id.push(BASE62[rng.random_range(0..62)] as char);
|
||||
}
|
||||
|
||||
PasteId(Cow::Owned(id))
|
||||
@ -227,7 +227,7 @@ Before we continue, we'll need to make a few design decisions.
|
||||
```toml
|
||||
[dependencies]
|
||||
## existing Rocket dependencies...
|
||||
rand = "0.8"
|
||||
rand = "0.9"
|
||||
```
|
||||
|
||||
Ensure that your application builds with the new code:
|
||||
|
||||
@ -15,7 +15,7 @@ rocket = { path = "../../core/lib", features = ["secrets"] }
|
||||
rocket = { path = "../../core/lib", features = ["secrets", "json", "mtls"] }
|
||||
figment = { version = "0.10.17", features = ["toml", "env"] }
|
||||
tokio = { version = "1", features = ["macros", "io-std"] }
|
||||
rand = "0.8"
|
||||
rand = "0.9"
|
||||
|
||||
[dev-dependencies.rocket_dyn_templates]
|
||||
path = "../../contrib/dyn_templates"
|
||||
|
||||
@ -9,4 +9,4 @@ publish = false
|
||||
rocket = { path = "../../core/lib", features = ["json"] }
|
||||
|
||||
[dev-dependencies]
|
||||
rand = "0.8"
|
||||
rand = "0.9"
|
||||
|
||||
@ -1,7 +1,7 @@
|
||||
use std::ops::Range;
|
||||
|
||||
use rand::{thread_rng, Rng};
|
||||
use rand::distributions::Alphanumeric;
|
||||
use rand::{rng, Rng};
|
||||
use rand::distr::Alphanumeric;
|
||||
|
||||
use rocket::http::{ContentType, Status};
|
||||
use rocket::http::uri::fmt::{UriDisplay, Query};
|
||||
@ -22,9 +22,9 @@ async fn send_message<'c>(client: &'c Client, message: &Message) -> LocalRespons
|
||||
}
|
||||
|
||||
fn gen_string(len: Range<usize>) -> String {
|
||||
thread_rng()
|
||||
rng()
|
||||
.sample_iter(&Alphanumeric)
|
||||
.take(thread_rng().gen_range(len))
|
||||
.take(rng().random_range(len))
|
||||
.map(char::from)
|
||||
.collect()
|
||||
}
|
||||
@ -42,7 +42,7 @@ async fn messages() {
|
||||
|
||||
// Generate somewhere between 75 and 100 messages.
|
||||
let mut test_messages = vec![];
|
||||
for _ in 0..thread_rng().gen_range(75..100) {
|
||||
for _ in 0..rng().random_range(75..100) {
|
||||
test_messages.push(Message {
|
||||
room: gen_string(10..30),
|
||||
username: gen_string(10..20),
|
||||
@ -98,7 +98,7 @@ async fn messages() {
|
||||
async fn bad_messages() {
|
||||
// Generate a bunch of bad messages.
|
||||
let mut bad_messages = vec![];
|
||||
for _ in 0..thread_rng().gen_range(75..100) {
|
||||
for _ in 0..rng().random_range(75..100) {
|
||||
bad_messages.push(Message {
|
||||
room: gen_string(30..40),
|
||||
username: gen_string(20..30),
|
||||
|
||||
@ -7,4 +7,4 @@ publish = false
|
||||
|
||||
[dependencies]
|
||||
rocket = { path = "../../core/lib" }
|
||||
rand = "0.8"
|
||||
rand = "0.9"
|
||||
|
||||
@ -17,9 +17,9 @@ impl PasteId<'_> {
|
||||
const BASE62: &[u8] = b"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";
|
||||
|
||||
let mut id = String::with_capacity(size);
|
||||
let mut rng = rand::thread_rng();
|
||||
let mut rng = rand::rng();
|
||||
for _ in 0..size {
|
||||
id.push(BASE62[rng.gen::<usize>() % 62] as char);
|
||||
id.push(BASE62[rng.random_range(0..62)] as char);
|
||||
}
|
||||
|
||||
PasteId(Cow::Owned(id))
|
||||
|
||||
@ -12,7 +12,7 @@ diesel_migrations = "2.0.0"
|
||||
|
||||
[dev-dependencies]
|
||||
parking_lot = "0.12"
|
||||
rand = "0.8"
|
||||
rand = "0.9"
|
||||
|
||||
[dependencies.rocket_sync_db_pools]
|
||||
path = "../../contrib/sync_db_pools/lib/"
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
use super::task::Task;
|
||||
|
||||
use rand::{Rng, thread_rng, distributions::Alphanumeric};
|
||||
use rand::{self, Rng, distr::Alphanumeric};
|
||||
|
||||
use rocket::local::asynchronous::Client;
|
||||
use rocket::http::{Status, ContentType};
|
||||
@ -103,7 +103,7 @@ fn test_many_insertions() {
|
||||
|
||||
for i in 0..ITER {
|
||||
// Issue a request to insert a new task with a random description.
|
||||
let desc: String = thread_rng()
|
||||
let desc: String = rand::rng()
|
||||
.sample_iter(&Alphanumeric)
|
||||
.take(12)
|
||||
.map(char::from)
|
||||
|
||||
Loading…
Reference in New Issue
Block a user