In Learning Rust With Entirely Too Many Linked Lists, they show that a pub enum
can\'t hold a private struct
:,
struct Node {
el
In the first example, the enum List
is public. That means that the enum variant More
is also public. However, More
cannot be used by external code because Node
isn't public. Thus, you have a thing that is externally visible, but can't actually be used, which is probably not what you wanted.
In the second example, the struct List
is public. However, the head
field is not public. Thus, it doesn't matter whether Link
is public or not, because external code can't see the head
field in the first place.