#@import struct from zon

1 messages · Page 1 of 1 (latest)

cold ether
#

It's my first time using zon and I'm confused, cuz I don't think you can specify the type in zon, and then when you try to assign the struct to a different variable the type doesn't match - expected type 'Target.Query', found 'build.build_zig_zon__struct_67147'

lapis totem
#

What does your zon look like?

cold ether
#

.{
...
.default_target = .{ .os_tag = .linux, .abi = .gnu, .cpu_arch = .x86_64, .android_api_level = 21 },
...
}

lapis totem
#

and how are you importing it?

cold ether
#

const build_zig_zon = @import("build.zig.zon");

lapis totem
#

I think you should specify the type to coerce to const zon: T = ...

cold ether
#

Is there no way to do that automatically? That's really inconenient

lapis totem
#

it would be equivalent to writing:

const zon = .{
...
    .default_target = .{ .os_tag = .linux, .abi = .gnu, .cpu_arch = .x86_64, .android_api_level = 21 },
...
}
#

so not really

cold ether
#

yeah ig that makes sense
Is there no way to turn one struct type to another?

#

When the fields are the same

lapis totem
#

it does that automatically

#

but only when its RLS

#

this would coerce because it has the result location

const x: T = .{};
#

this doesn't

const x = .{};
const y: T = x;
cold ether
#

Okay
Well that inconvenient
Thank you

lapis totem
#

you can just specify your own custom type of course

cold ether
#

?

lapis totem
#
const zon: struct {default_target: std.Target.Query} = ...;
#

i think the fields match

cold ether
#

Oh yeah okay