Is it possible to access a private struct field from a test?

Viewed 2421

I'm learning Rust at the moment (1 week so far) and I want to test my code.

I have this struct:

pub struct MyStruct {
  pub field1: i64,
  field2: i64
}

impl MyStruct {
  pub fn new(a: i64) -> MyStruct {
    MyStruct { field1: a, field2: 0 }
  }
}

Now in a test in another module, I want to create a MyStruct with a specific field2, but it is private.

Is there a way to do it without creating a special constructor for MyStruct?

1 Answers
Related