I want to create a struct by calling new
member function of a given struct by initializing only some of the fields. I am getting an error error[E0063]: missing fields b and join_handle in initializer of B::B
. This is my sample code
main.rs
mod B;
mod A;
fn main() {
println!("Hello, world!");
}
A.rs
pub struct AS {
a: String
}
B.rs
use crate::A::AS;
use std::thread;
pub struct B {
a: String,
b: AS,
join_handle: thread::JoinHandle<()>
}
impl B {
fn new() -> B {
B {
a: String::from("Hi"),
}
}
}
How to partially initialize a struct?