1

I would like to initialized a struct which will only reference other fields it owns.

What's the rust way of writing something like this?

struct Foo {
    a: i32,
    b: &i32,
}

impl Foo {
    fn new() -> Self {
        Self {
            a: 0,
            b: &self.a,
        }
    }
}

thanks

elmarco
  • 31,633
  • 21
  • 64
  • 68

0 Answers0