thunk: add 0.14-dev compatibility shim

Various type definitions in std.builtin got renamed to avoid field/decl
collisions as was required for the implementation of decl literals.
Since this is the only thing busted, shim it and retain cross-version
support for now.
This commit is contained in:
torque 2024-09-15 21:08:40 -07:00
parent 5c340bef56
commit 68a98232a1
Signed by: torque
SSH Key Fingerprint: SHA256:nCrXefBNo6EbjNSQhv0nXmEg/VuNq3sMF5b8zETw3Tk

View File

@ -16,7 +16,49 @@ const std = @import("std");
const nats_c = @import("./nats_c.zig").nats_c;
pub fn checkUserDataType(comptime T: type) void {
pub fn CallbackType(comptime T: type) type {
return switch (@typeInfo(T)) {
.optional => |info| ?CallbackType(info.child),
.pointer => |info| switch (info.size) {
.Slice => *const T,
else => T,
},
else => *T,
};
}
pub const checkUserDataType = if (@hasField(std.builtin.Type, "optional"))
checkUserDataType_14
else
checkUserDataType_13;
pub fn checkUserDataType_14(comptime T: type) void {
switch (@typeInfo(T)) {
.optional => |info| switch (@typeInfo(info.child)) {
.optional => @compileError(
"nats callbacks can only accept an (optional) single, many," ++
" or c pointer as userdata. \"" ++
@typeName(T) ++ "\" has more than one optional specifier.",
),
else => checkUserDataType(info.child),
},
.pointer => |info| switch (info.size) {
.Slice => @compileError(
"nats callbacks can only accept an (optional) single, many," ++
" or c pointer as userdata, not slices. \"" ++
@typeName(T) ++ "\" appears to be a slice.",
),
else => {},
},
else => @compileError(
"nats callbacks can only accept an (optional) single, many," ++
" or c pointer as userdata. \"" ++
@typeName(T) ++ "\" is not a pointer type.",
),
}
}
pub fn checkUserDataType_13(comptime T: type) void {
switch (@typeInfo(T)) {
.Optional => |info| switch (@typeInfo(info.child)) {
.Optional => @compileError(