authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2021-08-31 17:01:57-07:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2021-09-01 17:54:07-07:00
logfeec4b0614c1fd64fa59634af8774a992c7a5646
treed0613028b86b6e4dd540f84ada64939d35deee4a
parentf4d3d29f925c370ec7a33e20fcce917bb90f48a8

langref: new usingnamespace semantics


1 files changed, 8 insertions(+), 19 deletions(-)

doc/langref.html.in+8-19
......@@ -5812,32 +5812,20 @@ test "@intToPtr for pointer to zero bit type" {
58125812
58135813 {#header_open|usingnamespace#}
58145814 <p>
5815 {#syntax#}usingnamespace{#endsyntax#} is a declaration that imports all the public declarations of
5816 the operand, which must be a {#link|struct#}, {#link|union#}, or {#link|enum#}, into the current scope:
5815 {#syntax#}usingnamespace{#endsyntax#} is a declaration that mixes all the public
5816 declarations of the operand, which must be a {#link|struct#}, {#link|union#}, {#link|enum#},
5817 or {#link|opaque#}, into the namespace:
58175818 </p>
58185819 {#code_begin|test|usingnamespace#}
5819usingnamespace @import("std");
5820
58215820test "using std namespace" {
5822 try testing.expect(true);
5823}
5824 {#code_end#}
5825 <p>
5826 {#syntax#}usingnamespace{#endsyntax#} can also be used in containers:
5827 </p>
5828 {#code_begin|test|usingnamespace_inside_struct#}
5829test "using namespace inside struct" {
5830 const L = struct {
5831 usingnamespace struct {
5832 pub fn f() void {}
5833 };
5821 const S = struct {
5822 usingnamespace @import("std");
58345823 };
5835 L.f();
5824 try S.testing.expect(true);
58365825}
58375826 {#code_end#}
58385827 <p>
5839 Instead of the above pattern, it is generally recommended to explicitly alias individual declarations.
5840 However, {#syntax#}usingnamespace{#endsyntax#} has an important use case when organizing the public
5828 {#syntax#}usingnamespace{#endsyntax#} has an important use case when organizing the public
58415829 API of a file or package. For example, one might have <code>c.zig</code> with all of the
58425830 {#link|C imports|Import from C Header File#}:
58435831 </p>
......@@ -5858,6 +5846,7 @@ pub usingnamespace @cImport({
58585846 </p>
58595847 {#header_close#}
58605848
5849
58615850 {#header_open|comptime#}
58625851 <p>
58635852 Zig places importance on the concept of whether an expression is known at compile-time.