Advertisement
Guest User

Untitled

a guest
Jun 27th, 2018
184
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.67 KB | None | 0 0
  1. const Allocator = @import("std").mem.Allocator;
  2.  
  3. pub const Inner = struct {
  4. allocator: Allocator,
  5. inner_field: i32,
  6. };
  7.  
  8. pub const Outer = struct {
  9. inner: Inner,
  10. outer_field: i32,
  11.  
  12. pub fn init() Outer {
  13. return Outer{
  14. .inner = Inner{
  15. .allocator = Allocator{
  16. .allocFn = alloc,
  17. .reallocFn = realloc,
  18. .freeFn = free,
  19. },
  20. .inner_field = 200,
  21. },
  22. .outer_field = 100,
  23. };
  24. }
  25.  
  26. fn alloc(allocator: *Allocator, n: usize, alignment: u29) ![]u8 {
  27. const inner = @fieldParentPtr(Inner, "allocator", allocator);
  28. const outer = @fieldParentPtr(Outer, "inner", inner);
  29.  
  30. etc...
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement