Right, so, what you're asking for isn't necessarily the same thing as what other people asking for "inheritance" (even "interface inheritance") typically want.
A lot of people who ask for inheritance specifically want to be able to do this:
struct interface Bar { ... }
struct Foo implements Bar { ... }
struct Baz implements Bar { ... }
struct Message {
value @0 :Bar;
# May contain a Foo or a Baz.
}
I think if we added a way to declare "struct interfaces" in capnp schema language, people would be confused to find that they can't actually use the interface type in their schemas.
It sounds like you're fine with that -- all you want is to be able to write code in whatever programming language which is polymorphic over struct types that have the right common subset of fields.
I think the right way to solve your problem really depends on the language:
- In dynamic languages, you just use duck typing.
- In C++, you can use templates (which provide compile-time duck typing).
- In languages with implicit interfaces (e.g. Go and Haskell) you can declare the interface in code and the capnp types will implicitly implement it.
- In Java, perhaps you need an annotation which you can use to tell the code generator to please declare the reader/builder as implementing some interface:
struct Foo $Java.readerExtends("com.example.Bar") { ... }
This would cause the code generator to add the appropriate "extends" declaration to your reader type; it's up to you to define the Bar interface separately.
-Kenton