ModularM
Modular16mo ago
14 replies
banananas

Using structs that inherit from a specific trait as a type?

If you have a trait and a struct that inherits from it, could you use that trait's children as a type in, for example, a list? E.g.:
trait MyTrait:
  fn __init__(inout self): ...

struct MyStruct(MyTrait):
  fn __init__(inout self): pass

fn main():
  let my_list = List[structs that inherit from MyTrait](MyStruct())
Was this page helpful?