From 993d5bc9c945a40815b4c9f119f67917961e6c9f Mon Sep 17 00:00:00 2001
From: Andrew Kelley
+ {#syntax#}usingnamespace{#endsyntax#} is a top level declaration that imports all the declarations of + the operand, which must be a {#link|struct#}, {#link|union#}, or {#link|enum#}, into the current scope: +
+ {#code_begin|test|usingnamespace#} +usingnamespace @import("std"); + +test "using std namespace" { + debug.assert(true); +} + {#code_end#} +
+ 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
+ API of a file or package. For example, one might have c.zig
with all of the
+ {#link|C imports|Import from C Header File#}:
+
{#syntax#} +pub usingnamespace @cImport({ + @cInclude("epoxy/gl.h"); + @cInclude("GLFW/glfw3.h"); + @cDefine("STBI_ONLY_PNG", ""); + @cDefine("STBI_NO_STDIO", ""); + @cInclude("stb_image.h"); +}); + {#endsyntax#}+
+ The above example demonstrates using {#syntax#}pub{#endsyntax#} to qualify the + {#syntax#}usingnamespace{#endsyntax#} additionally makes the imported declarations + {#syntax#}pub{#endsyntax#}. This can be used to forward declarations, giving precise control + over what declarations a given file exposes. +
+ {#header_close#} + {#header_open|comptime#}Zig places importance on the concept of whether an expression is known at compile-time.