ModularM
Modular3y ago
26 replies
moosems_yeehaw

Is struct inheritance implemented yet?

Can I make a struct inherit from another? For example can I take an Array that allows all types and make an inherited array that specializes in a singular type?

What I imagine doing (gets a compiler issue):
struct Example[T: AnyType]:
    var data: T
    
    fn __init__(inout self, info: T) -> None:
        self.data = info
        
struct InheritedExample[T: Int](Example):
    # The variable data and __init__ use T so it should be overwritten
    # and prevent unnecessary boilerplate
    pass
Was this page helpful?