Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

You return the type directly. You can then declare things to be of this type. Eg, from the Zig docs, here's how to construct a generic List type (note the comptime declaration of the generic parameter):

  fn List(comptime T: type) type {
      return struct {
          items: []T,
          len: usize,
      };
  }

  // The generic List data structure can be instantiated by passing in a type:
  var buffer: [10]i32 = undefined;
  var list = List(i32){
      .items = &buffer,
      .len = 0,
  };


Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: