Hacker News new | ask | show | jobs
by layer8 8 days ago
Rust doesn’t have implementation inheritance. If it did, it would need a constructor-like concept as well.
1 comments

With guaranteed RVO you could do something like this (pseudo-C):

   struct FooBase { ... }
   fn make_foo_base(...) -> FooBase
   struct Foo { base : FooBase; ... }
   fn make_foo(args...) -> Foo {
      return { .base = make_foo_base(...), ... }
   }
How is it ensured that make_foo will actually call make_foo_base?
Because it needs a FooBase to give as the value for .base or the struct initialization isn't valid because it doesn't give values for all the members?
You are right, sorry, lost track or the thread.