ModularM
Modular2y ago
5 replies
Martin Dudek

Best way to make a struct of CollectionElements to conform to CollectionElement.

I am still confused about best practices for __moveinit__ and __copyinit__.

Let's say i have a struct with two variables, which are both structs which conform to the CollectionElement trait, how to define __moveinit__ and __copyinit__ for this struct.

Will this do?

struct A:
  var b:B    # B conforms to CollectionElement
  var c:C    # C conforms to CollectionElement
  fn __init__(...

  fn __copyinit__(inout self, existing: Self):
      # ????
      self.b = existing.b
      self.c = existing.c
    
  fn __moveinit__(inout self, owned existing: Self):
      # ???
      self.b = existing.b
      self.c = existing.c

Any advice highly appreciated
Was this page helpful?