I'm new to Rust and for the first time I'm writing this sort of code:
#[tokio::main]
async fn main() {
#[derive(Default, Clone)]
pub struct Coach {
id: Option<i64>,
name: String,
team: Option<Team>
}
#[derive(Default, Clone)]
pub struct Team {
id: Option<i64>,
name: String,
coach: Option<Coach>
}
}
The error is:
error[E0072]: recursive type `Coach` has infinite size
--> src/main.rs:4:5
|
4 | pub struct Coach {
| ^^^^^^^^^^^^^^^^ recursive type has infinite size
...
7 | team: Option<Team>
| ------------ recursive without indirection
|
help: insert some indirection (e.g., a `Box`, `Rc`, or `&`) to make `Coach` representable
|
7 | team: Option<Box<Team>>
| ++++ +
error[E0072]: recursive type `Team` has infinite size
--> src/main.rs:11:5
|
11 | pub struct Team {
| ^^^^^^^^^^^^^^^ recursive type has infinite size
...
14 | coach: Option<Coach>
| ------------- recursive without indirection
|
help: insert some indirection (e.g., a `Box`, `Rc`, or `&`) to make `Team` representable
|
14 | coach: Option<Box<Coach>>
| ++++ +
For more information about this error, try `rustc --explain E0072`.
Coming from Go where something like this is easily possible, what is Rust idiomatic code?