authorgravatar for vegai@iki.fiVesa Kaihlavirta <vegai@iki.fi> 2019-09-04 20:02:31+03:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2019-09-05 13:07:04-04:00
log847a262efdf5f3a359b00f13c101236dc0747f1b
tree0db51a603234ec2e435816e12bbce1d3ded37324
parentfe153ad2a435e26f9904f05858232305bdffd3ac

Shorten @field documentation and add an example


1 files changed, 21 insertions(+), 3 deletions(-)

doc/langref.html.in+21-3
......@@ -6976,10 +6976,28 @@ export fn @"A function name that is a complete sentence."() void {}
69766976
69776977 {#header_open|@field#}
69786978 <pre>{#syntax#}@field(lhs: var, comptime field_name: []const u8) (field){#endsyntax#}</pre>
6979 <p>Preforms field access equivalent to {#syntax#}lhs.field_name{#endsyntax#}, except instead
6980 of the field {#syntax#}"field_name"{#endsyntax#}, it accesses the field named by the string
6981 value of {#syntax#}field_name{#endsyntax#}.
6979 <p>Performs field access by a compile-time string.
69826980 </p>
6981 {#code_begin|test#}
6982const std = @import("std");
6983
6984const Point = struct {
6985 x: u32,
6986 y: u32
6987};
6988
6989test "field access by string" {
6990 const assert = std.debug.assert;
6991 var p = Point {.x = 0, .y = 0};
6992
6993 @field(p, "x") = 4;
6994 @field(p, "y") = @field(p, "x") + 1;
6995
6996 assert(@field(p, "x") == 4);
6997 assert(@field(p, "y") == 5);
6998}
6999 {#code_end#}
7000
69837001 {#header_close#}
69847002
69857003 {#header_open|@fieldParentPtr#}