aboutsummaryrefslogtreecommitdiff
path: root/doc
diff options
context:
space:
mode:
authorAndrew Kelley <andrew@ziglang.org>2021-08-31 17:01:57 -0700
committerAndrew Kelley <andrew@ziglang.org>2021-09-01 17:54:07 -0700
commitfeec4b0614c1fd64fa59634af8774a992c7a5646 (patch)
treed0613028b86b6e4dd540f84ada64939d35deee4a /doc
parentf4d3d29f925c370ec7a33e20fcce917bb90f48a8 (diff)
downloadzig-feec4b0614c1fd64fa59634af8774a992c7a5646.tar.gz
zig-feec4b0614c1fd64fa59634af8774a992c7a5646.zip
langref: new usingnamespace semantics
Diffstat (limited to 'doc')
-rw-r--r--doc/langref.html.in27
1 files changed, 8 insertions, 19 deletions
diff --git a/doc/langref.html.in b/doc/langref.html.in
index cad6dee59f..00ed5752f5 100644
--- a/doc/langref.html.in
+++ b/doc/langref.html.in
@@ -5812,32 +5812,20 @@ test "@intToPtr for pointer to zero bit type" {
{#header_open|usingnamespace#}
<p>
- {#syntax#}usingnamespace{#endsyntax#} is a declaration that imports all the public declarations of
- the operand, which must be a {#link|struct#}, {#link|union#}, or {#link|enum#}, into the current scope:
+ {#syntax#}usingnamespace{#endsyntax#} is a declaration that mixes all the public
+ declarations of the operand, which must be a {#link|struct#}, {#link|union#}, {#link|enum#},
+ or {#link|opaque#}, into the namespace:
</p>
{#code_begin|test|usingnamespace#}
-usingnamespace @import("std");
-
test "using std namespace" {
- try testing.expect(true);
-}
- {#code_end#}
- <p>
- {#syntax#}usingnamespace{#endsyntax#} can also be used in containers:
- </p>
- {#code_begin|test|usingnamespace_inside_struct#}
-test "using namespace inside struct" {
- const L = struct {
- usingnamespace struct {
- pub fn f() void {}
- };
+ const S = struct {
+ usingnamespace @import("std");
};
- L.f();
+ try S.testing.expect(true);
}
{#code_end#}
<p>
- Instead of the above pattern, it is generally recommended to explicitly alias individual declarations.
- However, {#syntax#}usingnamespace{#endsyntax#} has an important use case when organizing the public
+ {#syntax#}usingnamespace{#endsyntax#} has an important use case when organizing the public
API of a file or package. For example, one might have <code>c.zig</code> with all of the
{#link|C imports|Import from C Header File#}:
</p>
@@ -5858,6 +5846,7 @@ pub usingnamespace @cImport({
</p>
{#header_close#}
+
{#header_open|comptime#}
<p>
Zig places importance on the concept of whether an expression is known at compile-time.