Consider the following code
struct Node {
elem: i32,
next: List,
}
pub enum List {
Empty,
More(Box<Node>),
}
This will make the compiler complain:
error[E0446]: private type `Node` in public interface
--> src/main.rs:8:10
|
8 | More(Box<Node>),
| ^^^^^^^^^^ can't leak private type
But this code will not result in an error, even if it Link
is private:
pub struct List {
head: Link,
}
enum Link {
Empty,
More(Box<Node>),
}
struct Node {
elem: i32,
next: Link,
}
What is the reason for this mismatch? Why does private enumeration not cause an error while the private structure is being executed?
source
share