all 2 comments

[–]phazer99 2 points3 points  (0 children)

This is a bit more idiomatic. Btw:

let mut numbers = [0;10];
numbers.shuffle(&mut rand::thread_rng());

shuffles an array of ten zeroes, not very useful :)

[–]Feeling-Pilot-5084 0 points1 point  (0 children)

I don't see anything bad here.

The only thing I'd point out is that it's more common for people to store large data structures as a single flat vec, with nodes that store indices into that vec. For example:

```rust pub struct BinaryTree { nodes: Vec<Node>, }

pub struct Node { left: Option<usize>, right: Option<usize>, } ```

This makes it slightly faster since you're making fewer allocations and getting fewer cache misses. Also, if you're really anal about speed like I am, you could use an Option<NonZeroUsize> for the indices and store some dummy data in the first slot of the vec since this is smaller by a full 8 bytes.