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

Here's how you return a hashmap from a function:

  fn buildMap(allocator: std.mem.Allocator) !std.AutoHashMap(u64, u64) {
      var result = std.AutoHashMap(u64, u64).init(allocator);
      errdefer result.deinit();
      try result.put(10, 100);
      try result.put(20, 200);
      return result;
  }
Your #1 option should be possible once Zig has comptime allocators -- it's on the roadmap, but not possible yet iirc.


If I remember correctly I tried almost exactly that, I think it was just the bang operator I missed out (obviously essential in this case).

Cheers for letting me know though!




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

Search: