structAlloc<X extends RaylibStruct<X>> method

RaylibTempStructAllocator<X> structAlloc<X extends RaylibStruct<X>>([
  1. StructType<X>? struct
])

Gets (or creates) a struct allocator.

Implementation

RaylibTempStructAllocator<X> structAlloc<X extends RaylibStruct<X>>([StructType<X>? struct]) {
  if (!StructTypes.exists<X>()) {
    if (struct == null) throw StateError(
      'Allocator for $X does not exist. If you want to register it, pass the `struct`.'
    );
    StructTypes.register(struct);
  }

  final map = StructTypes.isBuiltIn<X>()
    ? _builtInStructAllocators
    : _customStructAllocators;
  return (map[X] ??= RaylibTempStructAllocator<X>(this, StructTypes.of<X>())) as RaylibTempStructAllocator<X>;
}