Tuple struct constructor complains about private fields

As the error message suggests, the problem is JobsList has a private field, that is, the Vec<Job> value is inaccessible outside the module that defines the struct. This means that you cannot pattern match on a JobsList value to extract it, and that you cannot construct it directly.

There are two fixes:

  • make the field public pub struct JobsList(pub Vec<Job>);

  • provide a public constructor

      impl JobsList {
          pub fn new(jobs: Vec<Job>) -> JobsList {
              JobsList(jobs)
          }
      }
    

    called like JobsList::new(vec![]).

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)