field of struct is private when importing module

后端 未结 2 830
长情又很酷
长情又很酷 2021-01-07 19:22

I am trying to split my project into multiple files but I am having problems importing them into my main.rs as it says the Column\'s fields are private but I ha

相关标签:
2条回答
  • 2021-01-07 19:55

    Try labeling the fields as public:

    pub struct Column {
        pub name: String,
        pub vec: Vec<i32>,
    }
    

    Labeling Column as pub means that other modules can use the struct itself, but not necessarily all of its members.

    0 讨论(0)
  • 2021-01-07 19:58

    You've declared the struct as public, but not the fields. To make both fields public, the struct declaration should look as follows:

    pub struct Column {
        pub name: String,
        pub vec: Vec<i32>,
    }
    
    0 讨论(0)
提交回复
热议问题