Hello all,
I appreciate all you folks helping others learn to use Rust. I am a newbie with Rust, I do a little bit then do a little bit more. Now, I trying to use Rust structures. I posted a question a few days ago about how to define hierarchical data. Now I am trying to initialize that data. The compiler gives this error:
error[E0308]: mismatched types
--> src/main.rs:48:29
|
48 | coach: String::new(),
| ^^^^^^^^^^^^^ expected struct `Coach`, found struct `std::string::String`
error: aborting due to previous error
For more information about this error, try `rustc --explain E0308`.
error: could not compile `struct-test`.
My code is:
/*
structure declarations
*/
#[derive(Debug)]
struct Baseball {
teams: Vec<Team>,
}
#[derive(Debug)]
struct Team {
team_name: String,
mascot_name: String,
coach: Coach,
}
#[derive(Debug)]
struct Coach {
name: String,
experience_years: u32,
years_hd_coach: u32,
win_lose: (u32,u32),
asst_coaches: Vec<AsstCoach>,
}
#[derive(Debug)]
struct AsstCoach {
name: String,
experience_years: u32,
coach_of: String,
players: Vec<Players>,
}
#[derive(Debug)]
struct Players {
name: String,
position: String,
experience_years: u32,
errors_game: u32,
batting_avg: u32,
}
/*
start of main
*/
fn main() {
let mut baseball = Baseball {
teams: Vec::new(),
};
let mut team = Team {
team_name: String::new(),
mascot_name: String::new(),
coach: String::new(),
};
let mut coach = Coach {
name: String::new(),
experience_years: 0,
years_hd_coach: 0,
win_lose: (0,0),
asst_coaches: Vec::new(),
};
let mut asstcoach = AsstCoach {
name: String::new(),
experience_years: 0,
coach_of: String::new(),
players: Vec::new(),
};
let mut players = Players {
name: String::new(),
position: String::new(),
experience_years: 0,
errors_game: 0,
batting_avg: 0,
};
println!("content of structures: {:?}, {:?}, {:?}, {:?}, {:?}", baseball, team, coach, asstcoach, players);
}
Thanks for any help
rustuser99