mirror of
https://github.com/rust-lang-nursery/rust-cookbook
synced 2024-11-22 03:23:05 +00:00
removed unsafe block from rand-choose.md (#536)
the unsafe block in this example is not necessary and might confuse beginners.
This commit is contained in:
parent
3d90852592
commit
6d3f7f97a2
1 changed files with 1 additions and 2 deletions
|
@ -19,8 +19,7 @@ fn main() {
|
||||||
let password: String = (0..PASSWORD_LEN)
|
let password: String = (0..PASSWORD_LEN)
|
||||||
.map(|_| {
|
.map(|_| {
|
||||||
let idx = rng.gen_range(0, CHARSET.len());
|
let idx = rng.gen_range(0, CHARSET.len());
|
||||||
// This is safe because `idx` is in range of `CHARSET`
|
CHARSET[idx] as char
|
||||||
char::from(unsafe { *CHARSET.get_unchecked(idx) })
|
|
||||||
})
|
})
|
||||||
.collect();
|
.collect();
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue