replace usages of @Type
Some checks failed
aws-zig nightly build / build-zig-nightly (push) Failing after 6m14s
Some checks failed
aws-zig nightly build / build-zig-nightly (push) Failing after 6m14s
This commit is contained in:
parent
b9a18d30b4
commit
9b870aa969
2 changed files with 50 additions and 56 deletions
49
src/aws.zig
49
src/aws.zig
|
|
@ -1057,45 +1057,37 @@ fn ServerResponse(comptime action: anytype) type {
|
||||||
const ResponseMetadata = struct {
|
const ResponseMetadata = struct {
|
||||||
RequestId: []u8,
|
RequestId: []u8,
|
||||||
};
|
};
|
||||||
const Result = @Type(.{
|
const Result = @Struct(
|
||||||
.@"struct" = .{
|
.auto,
|
||||||
.layout = .auto,
|
null,
|
||||||
.fields = &[_]std.builtin.Type.StructField{
|
&[_][]const u8{ action.action_name ++ "Result", "ResponseMetadata" },
|
||||||
|
&[_]type{ T, ResponseMetadata },
|
||||||
|
&[_]std.builtin.Type.StructField.Attributes{
|
||||||
.{
|
.{
|
||||||
.name = action.action_name ++ "Result",
|
|
||||||
.type = T,
|
|
||||||
.default_value_ptr = null,
|
.default_value_ptr = null,
|
||||||
.is_comptime = false,
|
.@"comptime" = false,
|
||||||
.alignment = std.meta.alignment(T),
|
.@"align" = std.meta.alignment(T),
|
||||||
},
|
},
|
||||||
.{
|
.{
|
||||||
.name = "ResponseMetadata",
|
|
||||||
.type = ResponseMetadata,
|
|
||||||
.default_value_ptr = null,
|
.default_value_ptr = null,
|
||||||
.is_comptime = false,
|
.@"comptime" = false,
|
||||||
.alignment = std.meta.alignment(ResponseMetadata),
|
.@"align" = std.meta.alignment(ResponseMetadata),
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
.decls = &[_]std.builtin.Type.Declaration{},
|
);
|
||||||
.is_tuple = false,
|
return @Struct(
|
||||||
},
|
.auto,
|
||||||
});
|
null,
|
||||||
return @Type(.{
|
&[_][]const u8{action.action_name ++ "Response"},
|
||||||
.@"struct" = .{
|
&[_]type{Result},
|
||||||
.layout = .auto,
|
&[_]std.builtin.Type.StructField.Attributes{
|
||||||
.fields = &[_]std.builtin.Type.StructField{
|
|
||||||
.{
|
.{
|
||||||
.name = action.action_name ++ "Response",
|
|
||||||
.type = Result,
|
|
||||||
.default_value_ptr = null,
|
.default_value_ptr = null,
|
||||||
.is_comptime = false,
|
.@"comptime" = false,
|
||||||
.alignment = std.meta.alignment(Result),
|
.@"align" = std.meta.alignment(Result),
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
.decls = &[_]std.builtin.Type.Declaration{},
|
);
|
||||||
.is_tuple = false,
|
|
||||||
},
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
fn FullResponse(comptime action: anytype) type {
|
fn FullResponse(comptime action: anytype) type {
|
||||||
return struct {
|
return struct {
|
||||||
|
|
@ -1413,6 +1405,7 @@ fn reportTraffic(
|
||||||
|
|
||||||
test {
|
test {
|
||||||
_ = @import("aws_test.zig");
|
_ = @import("aws_test.zig");
|
||||||
|
_ = @import("servicemodel.zig");
|
||||||
}
|
}
|
||||||
|
|
||||||
// buildQuery/buildPath tests, which are here as they are a) generic and b) private
|
// buildQuery/buildPath tests, which are here as they are a) generic and b) private
|
||||||
|
|
|
||||||
|
|
@ -1,32 +1,27 @@
|
||||||
const std = @import("std");
|
const std = @import("std");
|
||||||
const service_list = @import("service_manifest");
|
const service_list = @import("service_manifest");
|
||||||
const expectEqualStrings = std.testing.expectEqualStrings;
|
|
||||||
|
|
||||||
pub fn Services(comptime service_imports: anytype) type {
|
pub fn Services(comptime service_imports: anytype) type {
|
||||||
if (service_imports.len == 0) return services;
|
if (service_imports.len == 0) return services;
|
||||||
// From here, the fields of our structure can be generated at comptime...
|
// From here, the fields of our structure can be generated at comptime...
|
||||||
var fields: [serviceCount(service_imports)]std.builtin.Type.StructField = undefined;
|
const fields_len = serviceCount(service_imports);
|
||||||
|
var field_names: [fields_len][]const u8 = undefined;
|
||||||
|
var field_types: [fields_len]type = undefined;
|
||||||
|
var field_attrs: [fields_len]std.builtin.Type.StructField.Attributes = undefined;
|
||||||
|
|
||||||
for (&fields, 0..) |*item, i| {
|
for (0..fields_len) |i| {
|
||||||
const import_field = @field(service_list, @tagName(service_imports[i]));
|
const import_field = @field(service_list, @tagName(service_imports[i]));
|
||||||
item.* = .{
|
field_names[i] = @tagName(service_imports[i]);
|
||||||
.name = @tagName(service_imports[i]),
|
field_types[i] = @TypeOf(import_field);
|
||||||
.type = @TypeOf(import_field),
|
field_attrs[i] = .{
|
||||||
.default_value_ptr = &import_field,
|
.default_value_ptr = &import_field,
|
||||||
.is_comptime = false,
|
.@"comptime" = false,
|
||||||
.alignment = std.meta.alignment(@TypeOf(import_field)),
|
.@"align" = std.meta.alignment(field_types[i]),
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
// finally, generate the type
|
// finally, generate the type
|
||||||
return @Type(.{
|
return @Struct(.auto, null, &field_names, &field_types, &field_attrs);
|
||||||
.@"struct" = .{
|
|
||||||
.layout = .auto,
|
|
||||||
.fields = &fields,
|
|
||||||
.decls = &[_]std.builtin.Type.Declaration{},
|
|
||||||
.is_tuple = false,
|
|
||||||
},
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn serviceCount(desired_services: anytype) usize {
|
fn serviceCount(desired_services: anytype) usize {
|
||||||
|
|
@ -39,17 +34,23 @@ fn serviceCount(desired_services: anytype) usize {
|
||||||
pub const services = service_list;
|
pub const services = service_list;
|
||||||
|
|
||||||
test "services includes sts" {
|
test "services includes sts" {
|
||||||
try expectEqualStrings("2011-06-15", services.sts.version.?);
|
try std.testing.expectEqualStrings("2011-06-15", services.sts.version.?);
|
||||||
}
|
}
|
||||||
test "sts includes get_caller_identity" {
|
test "sts includes get_caller_identity" {
|
||||||
try expectEqualStrings("GetCallerIdentity", services.sts.get_caller_identity.action_name);
|
try std.testing.expectEqualStrings("GetCallerIdentity", services.sts.get_caller_identity.action_name);
|
||||||
}
|
}
|
||||||
test "can get service and action name from request" {
|
test "can get service and action name from request" {
|
||||||
// get request object. This call doesn't have parameters
|
// get request object. This call doesn't have parameters
|
||||||
const metadata = services.sts.get_caller_identity.Request.metaInfo();
|
const metadata = services.sts.get_caller_identity.Request.metaInfo();
|
||||||
try expectEqualStrings("2011-06-15", metadata.service_metadata.version.?);
|
try std.testing.expectEqualStrings("2011-06-15", metadata.service_metadata.version.?);
|
||||||
}
|
}
|
||||||
test "can filter services" {
|
test "can filter services" {
|
||||||
const filtered_services = Services(.{ .sts, .wafv2 }){};
|
const filtered_services = Services(.{ .sts, .wafv2 }){};
|
||||||
try expectEqualStrings("2011-06-15", filtered_services.sts.version.?);
|
try std.testing.expectEqualStrings("2011-06-15", filtered_services.sts.version.?);
|
||||||
|
}
|
||||||
|
test "can reify type" {
|
||||||
|
const F = Services(.{.lambda});
|
||||||
|
const info = @typeInfo(F).@"struct";
|
||||||
|
try std.testing.expectEqual(@as(usize, 1), info.fields.len);
|
||||||
|
try std.testing.expectEqualStrings("lambda", info.fields[0].name);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue