mirror of
https://github.com/vlang/v.git
synced 2023-08-10 21:13:21 +03:00
33 lines
360 B
V
33 lines
360 B
V
struct Aa {
|
|
sub Bb
|
|
}
|
|
|
|
struct AaWithAliasType {
|
|
sub Bb
|
|
}
|
|
|
|
type AliasType = Bb
|
|
|
|
struct Bb {
|
|
a int
|
|
}
|
|
|
|
fn encode_struct[U](val U) {
|
|
$for field in U.fields {
|
|
_ = struct {
|
|
...val.$(field.name)
|
|
}
|
|
}
|
|
}
|
|
|
|
fn main() {
|
|
aa := Aa{}
|
|
bb := Bb{}
|
|
aa_with_alias_type := AaWithAliasType{}
|
|
|
|
encode_struct(aa)
|
|
encode_struct(aa_with_alias_type)
|
|
|
|
encode_struct(bb)
|
|
}
|