Fuji
Fuji

Reputation: 29834

"field `0` of struct is private" error on pub struct attribute

"field 0 of struct is private" error on pub struct attribute

In crate

pub struct A(String, String);

pub struct C {
    pub b: Vec<A>,
}

in main()

...iter().map(|my_tuple:&A| (my_tuple.0.parse::<f64>().unwrap()));


Why do I get an "struct is private" error when the attribute is pub, the struct is pub and the parent struct is pub?

Upvotes: 0

Views: 3498

Answers (1)

Michael Anderson
Michael Anderson

Reputation: 73520

You need to make the pieces of the tuple type A pub. Something like this:

pub struct A(pub String, pub String)

Upvotes: 7

Related Questions