-2

If I have structs A and B:

struct B {}

struct A<'a> {
  id: i32,
  b: &'a B
}

impl A<'_> {
  fn new() -> A {
    id: 3,
    b: // I have no B at the moment, how to create a A without B?
  }
}

I would like to create A, then assign &B to it later.

kmdreko
  • 42,554
  • 6
  • 57
  • 106
En Xie
  • 510
  • 4
  • 19

1 Answers1

2

Why not use Option? Rust doesn't have null, thankfully.

Riwen
  • 4,734
  • 2
  • 19
  • 31