Logo

Programming-Idioms

History of Idiom 17 > diff from v46 to v47

Edit summary for version 47 by berek:
[Rust] Box is unnecessary, because Vec already provides an indirection

Version 46

2019-09-29, 15:38:22

Version 47

2020-04-29, 09:24:07

Idiom #17 Create a Tree data structure

The structure must be recursive. A node may have zero or more children. A node has access to children nodes, but not to its parent.

Idiom #17 Create a Tree data structure

The structure must be recursive. A node may have zero or more children. A node has access to children nodes, but not to its parent.

Code
struct Node<T> {
  value: T,
  children: Vec<Box<Node<T>>>,
}
Code
struct Node<T> {
  value: T,
  children: Vec<Node<T>>,
}
Comments bubble
Must be boxed. Size must be known at compile time