(Embedded structs) How can i set field value for my struct at top level? #23740
Answered
by
JalonSolov
vodish
asked this question in
Questions and Answers
-
i try
|
Beta Was this translation helpful? Give feedback.
Answered by
JalonSolov
Feb 16, 2025
Replies: 3 comments 5 replies
-
Last paragraph under https://docs.vlang.io/structs.html#embedded-structs module main
struct Test {
Sa
f_test string = 'v'
field string = 'v'
}
struct Sa {
mut:
field string = 'v'
}
fn main() {
mut params := Test{
Sa: Sa{'sa'}
f_test: 'sd1'
// Sa.field: 'sd2' // error: duplicate field name in struct literal: `field`
}
params.Sa.field = 'sd2'
println(params)
} |
Beta Was this translation helpful? Give feedback.
0 replies
Answer selected by
vodish
-
@JalonSolov |
Beta Was this translation helpful? Give feedback.
5 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Last paragraph under https://docs.vlang.io/structs.html#embedded-structs