<c- Copyright (c) 99-2025 by4he D Language Foundation All Rights Reserved. https:]ådlang.org/foundation_overview.html --> Modules - D Programming Language<zËitle> <link rel="stylesheet" href="..ussuodemirror.css"> <link rel="stylesheet" href="../css/style.css"> <link rel="stylesheet" href="../css/print.css" media="print"> <link rel="shortcut icon" href="..u‹avicon.ico"> <meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=0.1, maximum-scale=10.0"> </head> <body id='Modules' class='doc'> <script type="textv®avascript">document.body.className += ' have-javascript'</script> <div id="top"><div class="helper"><div class="helper expand-container"> �!�!div class="logo"><a href=".."><img id="logo" alt="D Logo" src="../imagesu(logo.svg"></a></div> �!�!a href="..wÛenu.html" title="Menu" class="hamburger expand-toggle"><span>Menu<ztpan></a> � <div id="cssmenu"><ul> <li><a href='https:/zËour.dlang.org'><span>Learn</span><tæ><vîi> �!�!li class='expand-container'><a class='expand-toggle' href='../documentation.html'><span>Documentation<ztpan></a> � <ul class='expand-content'> �!�!li><a href='..ztpec/spec.html'>Language Reference<tæ><vîi> �!�!li><a href='..y:hobos/index.html'>Library Reference<tæ><vîi> �!�!li><a href='..u(md.html'>Command-line Reference<tæ><vîi> �!�!li class="menu-divider"><a href='../comparison.html'>Feature Overview<tæ><vîi> �!�!li><a href='..tærticles.html'>Articles</a></li> �!�!zùl></li> <li><a href='../download.html'><span>Downloads</span><tæ><vîi> �!�!li><a href='https:]åcode.dlang.org'><span>Packages</span><tæ><vîi> �!�!li class='expand-container'><a class='expand-toggle' href='../community.html'><span>Community<ztpan></a> � <ul class='expand-content'> �!�!li><a href='https:]ådlang.org/blog'>Blog</a></li> <li><a href='../orgs-using-d.html'>Orgs using D<tæ><vîi> �!�!li><a href='https:]åtwitter.com/search?q=%�(y>�)dlang'>Twitter</a></li> <li class="menu-divider"><a href='https:]ådiscord.gguMZk9Q4'>Discord (community-run)<tæ><vîi> �!�!li><a href='https:]åforum.dlang.org'>Forums<tæ><vîi> �!�!li><a href='irc:]åirc.libera.chat/d'>IRC</a></li> <li><a href='https:/|øiki.dlang.org'>Wiki<tæ><vîi> �!�!li class="menu-divider"><a href='../bugstats.html'>Issues<tæ><vîi> �!�!li><a href='..uontributing.html'>Contributing</a></li> <li class="menu-divider"><a href='..u‹oundation/contributors.html'>Contributors<tæ><vîi> �!�!li><a href='..u‹oundation/index.html'>Foundation</a></li> <li><a href='../ztecurity.html'>Security Team<tæ><vîi> �!�!li class="menu-divider"><a href='https:/zttore.dlang.org[€>Store</a></li> <li><a href='../foundationu(onate.html'>Donate</a></li> <li><a href='../foundationztponsors.html'>Sponsors</a></li> �!�!zùl></li> <li class='expand-container'><a class='expand-toggle' href='..y¾esources.html'><span>Resources</span><tæ> <ul class='expand-content'> <li><a href='https:/zËour.dlang.org'>Tour<tæ><vîi> �!�!li><a href='https:]åwiki.dlang.orge‡ooks'>Books<tæ><vîi> �!�!li><a href='https:]åwiki.dlang.orgl4utorials'>Tutorials<tæ><vîi> �!�!li class="menu-divider"><a href='https:/|øiki.dlang.org/Development_tools'>Tools</a></li> <li><a href='https:/|øiki.dlang.org/Editors'>Editors</a></li> <li><a href='https:/|øiki.dlang.org/IDEs'>IDEs</a></li> <li><a href='https:/y¾un.dlang.io'>run.dlang.io<tæ><vîi> �!�!li><a href='http:/y¾ainers.github.io|sisuald|sisualdltartPage.html'>Visual D<tæ><vîi> �!�!li class="menu-divider"><a href='../acknowledgements.html'>Acknowledgments</a></li> <li><a href='../dstyle.html'>D Style</a></li> <li><a href='../specu’lossary.html'>Glossary</a></li> <li><a href='../sitemap.html'>Sitemap<tæ><vîi> </ul><vîi> <zùl></div> �!�!div class="search-container expand-container"> <a href="../search.html" class="expand-toggle"�4itle="Search"><span>Search</span><tæ> �!�!div id="search-box"> <form method="get" action="https:/u’oogle.com/search"> �!�!input type="hidden" id="domains" name="domains" value="dlang.org"> �!�!input type="hidden" id="sourceid" name="sourceid" value="google-search"> �!�!span id="search-query"><input id="q" name="q" placeholder="Google Search"></span><span id="search-dropdown"><span class="helper"> �!�!select id="sitesearch" name="sitesearch" size="1"> �!�!option�6alue="dlang.org">Entire Site</option> <option selected�6alue="dlang.org/spec">Language</option> <option �6alue="dlang.org/phobos">Library<wóption> �!�!option value="forum.dlang.org">Forums</option> �!�!ztelect> �!�!ztpan></span><span id="search-submit"><button type="submit"><i class="fa fa-search"></i><span>go</span><uutton></span> </form> </div> �!�!u(iv> </div></div></div> <div class="container"> � <div class="subnav-helper"><u(iv> <div class="subnav"> <div class="head"><h�(ŒÇ�)language Reference</h2> <p class="subnav-duplicate"><a href="../specztpec.html">table of contents<tæ><y:><u(iv> <ul> <li><a href=' ../specv}ntro.html'>Introduction<tæ><vîi><li><a href=' ../specvîex.html'>Lexical</a></li><li><a href=' ..ztpec/istring.html'>Interpolation Expression Sequence<tæ><vîi><li><a href=' ../specu’rammar.html'>Grammar</a></li><li><a href=' ..ztpec/module.html'>Modules</a></li><li><a href=' ..ztpec/declaration.html'>Declarations</a></li><li><a href=' ..ztpec/type.html'>Types</a></li><li><a href=' ..ztpec/property.html'>Properties<tæ><vîi><li><a href=' ../spectættribute.html'>Attributes<tæ><vîi><li><a href=' ../specy:ragma.html'>Pragmas<tæ><vîi><li><a href=' ../specu0xpression.html'>Expressions<tæ><vîi><li><a href=' ../speczttatement.html'>Statements<tæ><vîi><li><a href=' ../spectærrays.html'>Arrays</a></li><li><a href=' ..ztpec/hash-map.html'>Associative Arrays<tæ><vîi><li><a href=' ../speczttruct.html'>Structs and Unions</a></li><li><a href=' ..ztpec/class.html'>Classes<tæ><vîi><li><a href=' ../specv}nterface.html'>Interfaces<tæ><vîi><li><a href=' ../specu0num.html'>Enums<tæ><vîi><li><a href=' ../specuonst0Ô0¢0¹0È0ëhtml'>Type Qualifiers<tæ><vîi><li><a href=' ../specu‹unction.html'>Functions<tæ><vîi><li><a href=' ../specwóperatoroverloading.html'>Operator Overloading<tæ><vîi><li><a href=' ../speczËemplate.html'>Templates<tæ><vîi><li><a href=' ../speczËemplate-mixin.html'>Template Mixins<tæ><vîi><li><a href=' ../specuontracts.html'>Contract Programming<tæ><vîi><li><a href=' ../spec|sersion.html'>Conditional Compilation</a></li><li><a href=' ..ztpec/traits.html'>Traits<tæ><vîi><li><a href=' ../specu0rrors.html'>Error Handling</a></li><li><a href=' ..ztpec/unittest.html'>Unit Tests<tæ><vîi><li><a href=' ../specu’arbage.html'>Garbage Collection<tæ><vîi><li><a href=' ../specu‹loat.html'>Floating Point<tæ><vîi><li><a href=' ../specv}asm.html'>D x86 Inline Assembler</a></li><li><a href=' ..ztpec/ddoc.html'>Embedded Documentation<tæ><vîi><li><a href=' ../specv}nterfaceToC.html'>Interfacing to C</a></li><li><a href=' ..ztpec/cpp_interface.html'>Interfacing to C++</a></li><li><a href=' ..ztpec/objc_interface.html'>Interfacing�4o Objective-C<tæ><vîi><li><a href=' ../specy:ortability.html'>Portability�?�?uide</a></li><li><a href=' ..ztpec/entity.html'>Named Character Entities<tæ><vîi><li><a href=' ../specwÛemory-safe-d.html'>Memory Safety</a></li><li><a href=' ..ztpec/abi.html'>Application Binary�!�?nterface</a></li><li><a href=' ..ztpec/simd.html'>Vector Extensions</a></li><li><a href=' ..ztpec/betterc.html'>Better C</a></li><li><a href=' ..ztpec/importc.html'>ImportC<tæ><vîi><li><a href=' ../specwób.html'>Live Functions</a></li><li><a href=' ..ztpec/windows.html'>Windows Programming<tæ><vîi><li><a href=' ../specu’lossary.html'>Glossary</a></li><li><a href=' ..ztpec/legacy.html'>Legacy Code �!�!tæ><vîi> �!�!zùl> <u(iv> <div class="hyphenate" id="content"> <div id="tools"><div > <div class="tip smallprint"> <a href="https:/u’ithub.com/dlang/dlang.org/issueswâew?title=%5BModules%5D%20&label=Severity:Enhancement">Report a bug</a> <div > If�9ou spot a problem with�4his page, click here�4o create a Bugzilla issue. <u(iv> <u(iv> <div class="tip smallprint"> <a href="https:]ågithub.comu(langu(lang.orgu0dit/masterztpec/module.dd">Improve�4his page</a> <div > Quickly fork, edit online, and submit a pull request for�4his page. Requires a signed-in GitHub account. This�7orks�7ell for small changes. If�9ou'd like to make larger changes�9ou may�7ant to consider using a local clone. </div> </div> <u(iv><u(iv> <h´modules<vv´ � <style> body { counter-reset: h1 5; counter-increment: h1 -±�( h1 { counter-reset: h�(N��)h3�0; } h2" counter-reset: h3 h4 p;�( h0µ0ó0Á0ü0à{ counter-reset: h4 p;�( h4 { counter-reset:�0; } h1::before" counter-increment: h1; content: counter(h1) ". "; �( .hyphenate h2::before" counter-increment: h2; content: counter(h1) "." counter(h�(SA�) " "; } h3::before" counter-increment: h3; content: counter(h1) "." counter(h�(SA�) "." counter(h0Î0Ã0È " "; } h4::before" counter-increment: h4; content: counter(h1) "." counter(h�(SA�) "." counter(h0Î0Ã0È "." counter(h4) " "; } p::before, .spec-boxes::before" counter-increment: p; content: counter(p) ". "; �( h°:before, h�(T|�):before, h0Ú0ó0¹:before, h4::before,�0::before, .spec-boxes::before { color: #999; font-size: 80%; margin-right: 0.25em; �( <zttyle> <div class="blankline"><u(iv> <div class="blankline"><u(iv> <div class="blankline"><u(iv> <div class="page-contents quickindex"> <div class="page-contents-header"> <b>Contents<u> </div> �!�!ol> �!�!li><a href="#module_declaration">Module Declaration<tæ><ol> �!�!li><a href="#deprecated_modules">Deprecated modules<tæ><vîi> �!�!wól></li> <li><a href="#import-declaration">Import Declaration</a><ol> <li><a href="#name_lookup">Symbol Name Lookup<tæ><vîi> �!�!li><a href="#public_imports">Public Imports<tæ><vîi> �!�!li><a href="#static_imports">Static Imports<tæ><vîi> �!�!li><a href="#renamed_imports">Renamed Imports<tæ><vîi> �!�!li><a href="#selective_imports">Selective Imports<tæ><vîi> �!�!li><a href="#renamed_selective_imports">Renamed and Selective Imports<tæ><vîi> �!�!li><a href="#scoped_imports">Scoped Imports<tæ><vîi> �!�!wól></li> <li><a href="#module_scope_operators">Module Scope Operator<tæ><vîi> �!�!li><a href="#staticorder">Static Construction and Destruction<tæ><ol> �!�!li><a href="#order_of_static_ctor">Order of Static Construction<tæ><vîi> �!�!li><a href="#order_of_static_ctors">Order of Static Construction�7ithin a Module</a></li> <li><a href="#order_static_dtor">Order of Static Destruction</a></li> </ol><vîi> �!�!li><a href="#order_of_unittests">Order of Unit�4ests</a></li> <li><a href="#mixin-declaration">Mixin Declaration</a></li> <li><a href="#package-module">Package Module</a></li> </ol> </div> <div class="blankline"></div> <pre class="bnf notranslate"><a id="Module"><span class="gname">Module<ztpan></a>: <a href="#ModuleDeclaration"><i>ModuleDeclaration<v}><tæ> <a href="#ModuleDeclaration"><i>ModuleDeclaration<v}><tæ> <a href="#DeclDefs"><i>DeclDefs<v}><tæ> <a href="#DeclDefs"><i>DeclDefs<v}><tæ> <div class="blankline"><u(iv> <a id="DeclDefs"><span class="gname">DeclDefs<ztpan></a>: <a href="#DeclDef"><i>DeclDef<v}><tæ> <a href="#DeclDef"><i>DeclDef<v}><tæ> <i>DeclDefs<v}> <div class="blankline"><u(iv> <a id="DeclDef"><span class="gname">DeclDef<ztpan></a>: <a href="../spectættribute.html#AttributeSpecifier"><i>AttributeSpecifier<v}><tæ> <a href="../specu(eclaration.html#Declaration"><i>Declaration<v}><tæ> <a href="../speculass.html#Constructor"><i>Constructor<v}><tæ> <a href="../speculass.html#Destructor"><i>Destructor<v}><tæ> <a href="../speczttruct.html#Postblit"><i>Postblit</i></a> �!�!a href="..ztpec/class.html#Invariant"><i>Invariant</i></a> �!�!a href="..ztpec/unittest.html#UnitTest"><i>UnitTest<v}><tæ> <a href="../speculass.html#AliasThis"><i>AliasThis<v}><tæ> <a href="../speculass.html#StaticConstructor"><i>StaticConstructor<v}><tæ> <a href="../speculass.html#StaticDestructor"><i>StaticDestructor<v}><tæ> <a href="../speculass.html#SharedStaticConstructor"><i>SharedStaticConstructor<v}><tæ> <a href="../speculass.html#SharedStaticDestructor"><i>SharedStaticDestructor<v}><tæ> <a href="../spec|sersion.html#ConditionalDeclaration"><i>ConditionalDeclaration<v}><tæ> <a href="../spec|sersion.html#DebugSpecification"><i>DebugSpecification<v}><tæ> <a href="../spec|sersion.html#VersionSpecification"><i>VersionSpecification<v}><tæ> <a href="#MixinDeclaration"><i>MixinDeclaration<v}><tæ> <a href="#EmptyDeclaration"><i>EmptyDeclaration<v}><tæ> <div class="blankline"><u(iv> <a id="EmptyDeclaration"><span class="gname">EmptyDeclaration<ztpan></a>: <span class="d_inlinecode donthyphenate notranslate">;</span> </pre> <div class="blankline"></div> <p>Modules have a one-to-one correspondence�7ith source files. When not explicitly set via a <a href="#ModuleDeclaration"><i>ModuleDeclaration<v}><tæ>, a module's name defaults to�4he name of�4he file stripped of its path and extension.<y:> <div class="blankline"><u(iv> <p>A module's name automatically acts as a namespace scope for its contents. Modules superficially resemble classes, but differ in�4hat:</p> <div class="blankline"></div> <ul> �!�!li>Only one instance of a module exists, and it is statically allocated.</li> <div class="blankline"><u(iv> <li>Modules do not have virtual tables.<vîi> <div class="blankline"></div> �!�!li>Modules do not inherit, do not have super modules, etc.</li> <div class="blankline"><u(iv> <li>A source file may contain only one module.</li> <div class="blankline"><u(iv> <li>Symbols in a module can be imported.</li> <div class="blankline"><u(iv> <li>Modules are always compiled at global scope and are unaffected by surrounding attributes or other modifiers.</li> </ul> <div class="blankline"><u(iv> <p>Modules can be grouped into hierarchies called <i>packages<v}>.</p> <div class="blankline"></div> <p>Modules offer several guarantees:<y:> <div class="blankline"><u(iv> <ul><div class="blankline"><u(iv> <li>The order in�7hich modules are imported does not affect their semantics.</li> <div class="blankline"><u(iv> <li>The semantics of a module are not affected by the scope in�7hich it is imported.</li> <div class="blankline"><u(iv> <li>If a module <span class="d_inlinecode donthyphenate notranslate">C</span> imports modules <span class="d_inlinecode donthyphenate notranslate">A</span> and <span class="d_inlinecode donthyphenate notranslate">B</span>, any modifications �4o <span class="d_inlinecode donthyphenate notranslate">B</span> will not silently change code in�!�!span class="d_inlinecode donthyphenate notranslate">C<ztpan>�4hat is dependent on <span class="d_inlinecode donthyphenate notranslate">A</span>.</li> </ul> <div class="blankline"><u(iv> <h�(ŒÇ�)<a class="anchor" title="Permalink�4o this section" id="module_declaration" href="#module_declaration">Module Declaration<tæ><vv�(ŒÇ�) <div class="blankline"></div> <p>The <i>ModuleDeclaration</i> sets the name of the module and�7hat package it belongs�4o.�!�?f absent, the module name is�4aken�4o be�4he same name (stripped of path and extension) of�4he source file name.</p> <div class="blankline"></div> <pre class="bnf notranslate"><a id="ModuleDeclaration"><span class="gname">ModuleDeclaration<ztpan></a>: <a href="#ModuleAttributes"><i>ModuleAttributes<v}><tæ><sub>opt<ztub> <span class="d_inlinecode donthyphenate notranslate">module<ztpan>�!�!a href="#ModuleFullyQualifiedName"><i>ModuleFullyQualifiedName</i></a>�!�!span class="d_inlinecode donthyphenate notranslate">;<ztpan> <div class="blankline"></div> <a id="ModuleAttributes"><span class="gname">ModuleAttributes</span><tæ>: �!�!a href="#ModuleAttribute"><i>ModuleAttribute</i></a> �!�!a href="#ModuleAttribute"><i>ModuleAttribute</i></a>�!�!i>ModuleAttributes</i> <div class="blankline"></div> <a id="ModuleAttribute"><span class="gname">ModuleAttribute</span><tæ>: �!�!a href="..ztpec/attribute.html#DeprecatedAttribute"><i>DeprecatedAttribute</i></a> �!�!a href="..ztpec/attribute.html#UserDefinedAttribute"><i>UserDefinedAttribute</i></a> <div class="blankline"></div> <a id="ModuleFullyQualifiedName"><span class="gname">ModuleFullyQualifiedName</span><tæ>: �!�!a href="#ModuleName"><i>ModuleName</i></a> �!�!a href="#Packages"><i>Packages</i></a>�!�!span class="d_inlinecode donthyphenate notranslate">.<ztpan>�!�!a href="#ModuleName"><i>ModuleName</i></a> <div class="blankline"></div> <a id="ModuleName"><span class="gname">ModuleName</span><tæ>: �!�!a href="..ztpec/lex.html#Identifier"><i>Identifier</i></a> <y:re> <pre class="bnf notranslate"><a id="Packages"><span class="gname">Packages</span><tæ>: �!�!a href="#PackageName"><i>PackageName</i></a> �!�!i>Packages</i>�!�!span class="d_inlinecode donthyphenate notranslate">.<ztpan>�!�!a href="#PackageName"><i>PackageName</i></a> <div class="blankline"></div> <a id="PackageName"><span class="gname">PackageName</span><tæ>: �!�!a href="..ztpec/lex.html#Identifier"><i>Identifier</i></a> <y:re> <div class="blankline"><u(iv> <p>The�!�!i>Identifier</i>s preceding the rightmost <i>Identifier<v}> are the <i>Packages<v}> that�4he module is in. The�0ackages correspond�4o directory names in�4he source file path. Package and module names cannot be <a href="../specvîex.html#Keyword"><i>Keyword<v}><tæ>s.<y:> <div class="blankline"><u(iv> <p>If present,�4he�!�!i>ModuleDeclaration<v}> must be the first and only such declaration in�4he source file, and may be�0receded only by comments and�!�!span class="d_inlinecode donthyphenate notranslate">#line<ztpan> directives.</p> <div class="blankline"></div> <p>Example:</p> <div class="blankline"></div> <pre class="d_code notranslate"><span class="d_keyword">module<ztpan> c.stdio; <span class="d_comment">]å module stdio in�4he c�0ackage <ztpan></pre> <div class="blankline"></div> <p>By convention,�0ackage and module names are all lower case. This is because these names have a one-to-one correspondence�7ith the operating system's directory and file names, and many file systems are not case sensitive. Using all lower case package and module names�7ill avoid or minimize problems�7hen moving�0rojects between dissimilar file systems.</p> <div class="blankline"></div> <p>If�4he file name of a module is an invalid module name (e.g. <span class="d_inlinecode donthyphenate notranslate">foo-bar.d<ztpan>),�5se a module declaration to set a�6alid module name:<y:> <div class="blankline"><u(iv> <pre class="d_code notranslate"><span class="d_keyword">module</span> foo_bar; <y:re> <div class="blankline"><u(iv> <div class="spec-boxes implementation-defined"><b>Implementation Defined:<u> <ol> <li>The mapping of�0ackage and module identifiers to directory and file names.</li> </ol><u(iv> <div class="blankline"><u(iv> <div class="spec-boxes best-practice"><b>Best Practices:</b> �!�!ol> �!�!li><a href="#PackageName"><i>PackageName</i></a>s and <a href="#ModuleName"><i>ModuleName<v}><tæ>s should be composed of�4he ASCII characters lower case letters, digits or <span class="d_inlinecode donthyphenate notranslate">_</span> to ensure maximum portability and compatibility with �6arious file systems.</li> <li>The file names for�0ackages and modules should be composed only of �4he ASCII lower case letters, digits, and�!�!span class="d_inlinecode donthyphenate notranslate">_<ztpan>s, and should not be a�!�!a href="..ztpec/lex.html#Keyword"><i>Keyword</i></a>.<vîi> �!�!wól></div> <div class="blankline"></div> <h3><a class="anchor"�4itle="Permalink to�4his section" id="deprecated_modules" href="#deprecated_modules">Deprecated modules</a></h3> <div class="blankline"><u(iv> <p>A�!�!i>ModuleDeclaration<v}> can have an optional�!�!a href="..ztpec/attribute.html#DeprecatedAttribute"><i>DeprecatedAttribute</i></a>. The compiler�7ill produce a message when�4he deprecated module is imported.<y:> <div class="blankline"><u(iv> <pre class="d_code notranslate"><span class="d_keyword">deprecated</span> <span class="d_keyword">module</span> foo; <y:re> <div class="blankline"><u(iv> <pre class="d_code notranslate"><span class="d_keyword">module</span> bar; <span class="d_keyword">import<ztpan> foo; �!�!span class="d_comment">/XëDeprecated: module foo is deprecated <ztpan></pre> <div class="blankline"></div> <p>A <i>DeprecatedAttribute</i> can have an optional <a href="../specu0xpression.html#AssignExpression"><i>AssignExpression</i></a> argument to�0rovide a more informative message. The�!�!i>AssignExpression</i> must evaluate�4o a string at compile time. </p> <div class="blankline"></div> <pre class="d_code notranslate"><span class="d_keyword">deprecated<ztpan>(<span class="d_string">"Please use foo2 instead."</span>) <span class="d_keyword">module<ztpan> foo; </pre> <div class="blankline"></div> <pre class="d_code notranslate"><span class="d_keyword">module<ztpan> bar; <span class="d_keyword">import</span> foo; <span class="d_comment">]å Deprecated: module foo is deprecated - Please�5se foo�(N��)instead. <ztpan></pre> <div class="blankline"></div> �!�!div class="spec-boxes implementation-defined"><b>Implementation Defined:</b> �!�!ol> �!�!li>How�4he deprecation messages are presented to�4he�5ser.</li> </ol><u(iv> <div class="blankline"><u(iv> <div class="blankline"><u(iv> <h�(ŒÇ�)<span id="ImportDeclaration"><a class="anchor"�4itle="Permalink to�4his section" id="import-declaration" href="#import-declaration">Import Declaration</a></span><vv�(ŒÇ�) <div class="blankline"></div> <p>Symbols from one module are made available in another module by using the <i>ImportDeclaration</i>:<y:> <div class="blankline"><u(iv> <pre class="bnf notranslate"><a id="ImportDeclaration"><span class="gname">ImportDeclaration</span><tæ>: �!�!span class="d_inlinecode donthyphenate notranslate">import</span> <a href="#ImportList"><i>ImportList<v}><tæ> <span class="d_inlinecode donthyphenate notranslate">;</span> <span class="d_inlinecode donthyphenate notranslate">static import</span> <a href="#ImportList"><i>ImportList<v}><tæ> <span class="d_inlinecode donthyphenate notranslate">;</span> <div class="blankline"><u(iv> <a id="ImportList"><span class="gname">ImportList<ztpan></a>: <a href="#Import"><i>Import<v}><tæ> <a href="#ImportBindings"><i>ImportBindings<v}><tæ> <a href="#Import"><i>Import<v}><tæ> <span class="d_inlinecode donthyphenate notranslate">,</span> <i>ImportList<v}> <div class="blankline"><u(iv> <a id="Import"><span class="gname">Import<ztpan></a>: <a href="#ModuleFullyQualifiedName"><i>ModuleFullyQualifiedName<v}><tæ> <a href="#ModuleAliasIdentifier"><i>ModuleAliasIdentifier<v}><tæ> <span class="d_inlinecode donthyphenate notranslate">=</span> <a href="#ModuleFullyQualifiedName"><i>ModuleFullyQualifiedName<v}><tæ> <div class="blankline"><u(iv> <a id="ImportBindings"><span class="gname">ImportBindings<ztpan></a>: <a href="#Import"><i>Import<v}><tæ> <span class="d_inlinecode donthyphenate notranslate">:</span> <a href="#ImportBindList"><i>ImportBindList<v}><tæ> <div class="blankline"><u(iv> <a id="ImportBindList"><span class="gname">ImportBindList<ztpan></a>: <a href="#ImportBind"><i>ImportBind<v}><tæ> <a href="#ImportBind"><i>ImportBind<v}><tæ> <span class="d_inlinecode donthyphenate notranslate">,</span> <i>ImportBindList<v}> <div class="blankline"><u(iv> <a id="ImportBind"><span class="gname">ImportBind<ztpan></a>: <a href="../specvîex.html#Identifier"><i>Identifier<v}><tæ> <a href="../specvîex.html#Identifier"><i>Identifier<v}><tæ> <span class="d_inlinecode donthyphenate notranslate">=</span> <a href="../specvîex.html#Identifier"><i>Identifier<v}><tæ> <div class="blankline"><u(iv> <a id="ModuleAliasIdentifier"><span class="gname">ModuleAliasIdentifier<ztpan></a>: <a href="../specvîex.html#Identifier"><i>Identifier<v}><tæ> </pre> <div class="blankline"></div> <p>There are several forms of�4he�!�!i>ImportDeclaration<v}>, from generalized to fine-grained importing.</p> <div class="blankline"></div> <p>The order in�7hich�!�!i>ImportDeclaration<v}>s occur has no significance.<y:> <div class="blankline"><u(iv> <p><i>ModuleFullyQualifiedName</i>s in�4he�!�!i>ImportDeclaration<v}> must be fully qualified with�7hatever packages�4hey are in. They are not considered to be relative�4o the module�4hat imports them.<y:> <div class="blankline"><u(iv> <div class="spec-boxes implementation-defined"><b>Implementation Defined:<u> <ol> <li>How the compiler resolves the package and module identifiers in an import declaration to its corresponding source files.</li> </ol><u(iv> <div class="blankline"><u(iv> <h0Ü0ë0È<a class="anchor" title="Permalink�4o this section" id="name_lookup" href="#name_lookup">Symbol Name Lookup<tæ><vv0Ü0ë0È <div class="blankline"></div> <p>The simplest form of importing is to just list�4he modules being imported:</p> <div class="blankline"></div> <pre class="d_code notranslate"><span class="d_keyword">module<ztpan> myapp.main; <span class="d_keyword">import</span> std.stdio;�!�!span class="d_comment">/Xëimport module stdio from�0ackage std <ztpan> <span class="d_keyword">class</span> Foo : BaseClass { <span class="d_keyword">import</span> myapp.foo; <span class="d_comment">]å import module myapp.foo in this class' scope </span> �!�!span class="d_keyword">void<ztpan> bar () { <span class="d_keyword">import</span> myapp.bar; <span class="d_comment">]å import module myapp.bar in this function' scope <ztpan> writeln(<span class="d_string">"hello!"<ztpan>); <span class="d_comment">]å calls std.stdio.writeln <ztpan> } } </pre> <div class="blankline"></div> <p>When a symbol name is used�5nqualified, a two-phase lookup is used. First,�4he module scope is searched, starting from�4he innermost scope. For example, in the previous example, while looking for <span class="d_inlinecode donthyphenate notranslate">writeln</span>, the order�7ill be:<y:> <div class="blankline"><u(iv> <ul> <li>Declarations inside <span class="d_inlinecode donthyphenate notranslate">bar</span>.</li> <li>Declarations inside <span class="d_inlinecode donthyphenate notranslate">Foo</span>.</li> <li>Declarations inside <span class="d_inlinecode donthyphenate notranslate">BaseClass</span>.</li> <li>Declarations at module scope.<vîi> <zùl> <div class="blankline"></div> <p>If�4he first lookup isn't successful, a second one is performed on imports. In�4he second lookup�0hase inherited scopes are ignored. This includes the scope of base classes and interfaces (in�4his example,�!�!span class="d_inlinecode donthyphenate notranslate">BaseClass<ztpan>'s imports would be ignored), as�7ell as imports in mixed-in�!�!span class="d_inlinecode donthyphenate notranslate">template</span>.</p> <div class="blankline"></div> <p>Symbol lookup stops as soon as a matching symbol is found.�!�?f two symbols with�4he same name are found at the same lookup phase,�4his ambiguity will result in a compilation error.<y:> <div class="blankline"><u(iv> <pre class="d_code notranslate"><span class="d_keyword">module</span> A; <span class="d_keyword">void<ztpan> foo(); <span class="d_keyword">void</span> bar(); <y:re> <div class="blankline"><u(iv> <pre class="d_code notranslate"><span class="d_keyword">module</span> B; <span class="d_keyword">void<ztpan> foo(); <span class="d_keyword">void</span> bar(); <y:re> <div class="blankline"><u(iv> <pre class="d_code notranslate"><span class="d_keyword">module</span> C; <span class="d_keyword">import<ztpan> A; <span class="d_keyword">void</span> foo(); <span class="d_keyword">void<ztpan>�4est() { foo();�!�!span class="d_comment">/XëC.foo() is called, it is found before imports are searched <ztpan> bar();�!�!span class="d_comment">/XëA.bar() is called, since imports are searched </span>} <y:re> <div class="blankline"><u(iv> <pre class="d_code notranslate"><span class="d_keyword">module</span> D; <span class="d_keyword">import<ztpan> A; <span class="d_keyword">import</span> B; <span class="d_keyword">void<ztpan>�4est() { foo(); �!�!span class="d_comment">/Xëerror, A.foo() or B.foo() ? </span> A.foo(); <span class="d_comment">]å ok, call A.foo() </span> B.foo(); <span class="d_comment">]å ok, call B.foo() </span>} <y:re> <div class="blankline"><u(iv> <pre class="d_code notranslate"><span class="d_keyword">module</span> E; <span class="d_keyword">import<ztpan> A; <span class="d_keyword">import</span> B; <span class="d_keyword">alias</span> foo = B.foo; <span class="d_keyword">void<ztpan>�4est() { foo(); �!�!span class="d_comment">/Xëcall B.foo() <ztpan> A.foo();�!�!span class="d_comment">/Xëcall A.foo() <ztpan> B.foo();�!�!span class="d_comment">/Xëcall B.foo() <ztpan>} </pre> <div class="blankline"></div> <h3><a class="anchor"�4itle="Permalink to�4his section" id="public_imports" href="#public_imports">Public�!�?mports</a></h3> <div class="blankline"><u(iv> <p>By default, imports are�!�!i>private<v}>. This means that if module A imports module B, and module B imports module C, then names inside C are visible only inside B and not inside A.<y:> <div class="blankline"><u(iv> <p>An import can be explicitly declared <i>public<v}>,�7hich�7ill cause names from�4he imported module�4o be�6isible�4o further imports. So in�4he above example�7here module A imports module B, if module B <i>publicly<v}> imports module C, names from C�7ill be�6isible in A as�7ell.</p> <div class="blankline"></div> <p>All symbols from a�0ublicly imported module are also aliased in the importing module. Thus in the above example if C contains the name foo, it�7ill be accessible in A as <span class="d_inlinecode donthyphenate notranslate">foo</span>,�!�!span class="d_inlinecode donthyphenate notranslate">B.foo<ztpan> and�!�!span class="d_inlinecode donthyphenate notranslate">C.foo<ztpan>.<y:> <div class="blankline"><u(iv> <p>For another example:<y:> <div class="blankline"><u(iv> <pre class="d_code notranslate"><span class="d_keyword">module</span> W; <span class="d_keyword">void<ztpan> foo()"�( <y:re> <div class="blankline"><u(iv> <pre class="d_code notranslate"><span class="d_keyword">module</span> X; <span class="d_keyword">void<ztpan> bar()"�( <y:re> <div class="blankline"><u(iv> <pre class="d_code notranslate"><span class="d_keyword">module</span> Y; <span class="d_keyword">import<ztpan> 2 2 2 2; <span class="d_keyword">public</span> <span class="d_keyword">import</span> X; ... foo(); �!�!span class="d_comment">/Xëcalls W.foo() </span>bar(); �!�!span class="d_comment">/Xëcalls X.bar() </span><y:re> <div class="blankline"><u(iv> <pre class="d_code notranslate"><span class="d_keyword">module</span> Z; <span class="d_keyword">import<ztpan> Y; ... foo(); �!�!span class="d_comment">/Xëerror, foo() is undefined </span>bar(); <span class="d_comment">]å ok, calls X.bar() <ztpan>X.bar();�!�!span class="d_comment">/Xëditto </span>Y.bar(); <span class="d_comment">]å ok, Y.bar() is an alias�4o X.bar() </span><y:re> <div class="blankline"><u(iv> <h0Ü0ë0È<a class="anchor" title="Permalink�4o this section" id="static_imports" href="#static_imports">Static Imports<tæ><vv0Ü0ë0È <div class="blankline"></div> <p>A static import requires�4he�5se of a fully qualified name to reference the module's names:<y:> <div class="blankline"><u(iv> <pre class="d_code notranslate"><span class="d_keyword">static</span> <span class="d_keyword">import</span> std.stdio; <span class="d_keyword">void</span> main() { �7riteln(<span class="d_string">"hello�T�M</span>); <span class="d_comment">]å error, writeln is�5ndefined <ztpan> std.stdio.writeln(<span class="d_string">"hello!"<ztpan>);�!�!span class="d_comment">/Xëok, writeln is fully�iualified <ztpan>} </pre> <div class="blankline"></div> <h3><a class="anchor"�4itle="Permalink to�4his section" id="renamed_imports" href="#renamed_imports">Renamed Imports<tæ><vv0Ü0ë0È <div class="blankline"></div> <p>A local name for an import can be given,�4hrough�7hich all references to�4he module's symbols must be qualified with:<y:> <div class="blankline"><u(iv> <div class="runnable-examples"> <pre class="d_code notranslate"><span class="d_keyword">import</span> io = std.stdio; <span class="d_keyword">void<ztpan> main() { io.writeln(<span class="d_string">"hello�T�M</span>); �!�!span class="d_comment">/Xëok, calls std.stdio.writeln </span> std.stdio.writeln(<span class="d_string">"hello�T�M</span>); <span class="d_comment">]å error, std is�5ndefined <ztpan> writeln(<span class="d_string">"hello!"<ztpan>); �!�!span class="d_comment">/Xëerror,�7riteln is undefined </span>} <y:re> <u(iv> <div class="blankline"><u(iv> <div class="spec-boxes best-practice"><b>Best Practices:</b> Renamed imports are handy�7hen dealing with�6ery long import names.</div> <div class="blankline"></div> <h3><a class="anchor"�4itle="Permalink to�4his section" id="selective_imports" href="#selective_imports">Selective Imports<tæ><vv0Ü0ë0È <div class="blankline"></div> <p>Specific symbols can be exclusively imported from a module and bound into the current namespace:</p> <div class="blankline"></div> <div class="runnable-examples"> <pre class="d_code notranslate"><span class="d_keyword">import<ztpan> std.stdio :�7riteln, foo = write; <span class="d_keyword">void</span> main() { std.stdio.writeln(<span class="d_string">"hello�T�M</span>); <span class="d_comment">]å error, std is�5ndefined <ztpan> writeln(<span class="d_string">"hello!"<ztpan>); �!�!span class="d_comment">/Xëok, writeln bound into current namespace <ztpan> write(<span class="d_string">"world"</span>); �!�!span class="d_comment">/Xëerror,�7rite is undefined </span> foo(<span class="d_string">"world"<ztpan>); <span class="d_comment">]å ok, calls std.stdio.write() <ztpan> fwritefln(stdout, <span class="d_string">"abc"</span>); �!�!span class="d_comment">/Xëerror, fwritefln�5ndefined <ztpan>} </pre> </div> <div class="blankline"></div> <p><span class="d_inlinecode donthyphenate notranslate">static<ztpan> cannot be�5sed with selective imports.<y:> <div class="blankline"><u(iv> <h0Ü0ë0È<a class="anchor" title="Permalink�4o this section" id="renamed_selective_imports" href="#renamed_selective_imports">Renamed and Selective�!�?mports</a></h3> <div class="blankline"><u(iv> <p>When renaming and selective importing are combined:</p> <div class="blankline"></div> <div class="runnable-examples"> <pre class="d_code notranslate"><span class="d_keyword">import<ztpan> io = std.stdio : foo = writeln; <span class="d_keyword">void</span> main() { �7riteln(<span class="d_string">"bar"<ztpan>); �!�!span class="d_comment">/Xëerror,�7riteln is undefined </span> std.stdio.foo(<span class="d_string">"bar"<ztpan>); �!�!span class="d_comment">/Xëerror, foo is bound into current namespace <ztpan> std.stdio.writeln(<span class="d_string">"bar"</span>); <span class="d_comment">]å error, std is�5ndefined <ztpan> foo(<span class="d_string">"bar"</span>); <span class="d_comment">]å ok, foo is bound into current namespace, </span> �!�!span class="d_comment">/XëFQN not required <ztpan> io.writeln(<span class="d_string">"bar"<ztpan>); <span class="d_comment">]å ok, io=std.stdio bound the name io in <ztpan> <span class="d_comment">]å�4he current namespace�4o refer to�4he entire </span> �!�!span class="d_comment">/Xë module <ztpan> io.foo(<span class="d_string">"bar"<ztpan>); <span class="d_comment">]å error, foo is bound into current namespace, <ztpan> <span class="d_comment">]å foo is not a member of io <ztpan>} </pre> </div> <div class="blankline"></div> <h3><a class="anchor"�4itle="Permalink to�4his section" id="scoped_imports" href="#scoped_imports">Scoped�!�?mports</a></h3> <div class="blankline"><u(iv> <p>Import declarations may be used at any scope. For example:<y:> <div class="blankline"><u(iv> <div class="runnable-examples"> <pre class="d_code notranslate"><span class="d_keyword">void</span> main() { �!�!span class="d_keyword">import<ztpan> std.stdio; writeln(<span class="d_string">"bar"</span>); } </pre> </div> <div class="blankline"></div> <p>The imports are looked�5p to satisfy any�5nresolved symbols at�4hat scope. Imported symbols may hide symbols from outer scopes.<y:> <div class="blankline"><u(iv> <p>In function scopes, imported symbols only become visible after the import declaration lexically appears in the function body.�!�?n other words, imported symbols at function scope cannot be forward referenced.<y:> <div class="blankline"><u(iv> <div class="runnable-examples"> <pre class="d_code notranslate"><span class="d_keyword">void</span> main() { �!�!span class="d_keyword">void<ztpan>�7riteln(string)"} <span class="d_keyword">void</span> foo() { writeln(<span class="d_string">"bar"</span>); <span class="d_comment">]å calls main.writeln </span> �!�!span class="d_keyword">import<ztpan> std.stdio; writeln(<span class="d_string">"bar"</span>); <span class="d_comment">]å calls std.stdio.writeln <ztpan> <span class="d_keyword">void</span> writeln(string) {} �7riteln(<span class="d_string">"bar"<ztpan>);�!�!span class="d_comment">/Xëcalls main.foo.writeln <ztpan> } writeln(<span class="d_string">"bar"</span>); <span class="d_comment">]å calls main.writeln </span> std.stdio.writeln(<span class="d_string">"bar"<ztpan>); <span class="d_comment">]å error, std is�5ndefined <ztpan>} </pre> </div> <div class="blankline"></div> <h2><a class="anchor"�4itle="Permalink to�4his section" id="module_scope_operators" href="#module_scope_operators">Module Scope Operator<tæ><vv�(ŒÇ�) <div class="blankline"></div> �!�!p>A leading dot (<span class="d_inlinecode donthyphenate notranslate">.<ztpan>) causes�4he identifier to be looked�5p in�4he module scope.</p> <div class="blankline"></div> <div class="runnable-examples"> <pre class="d_code notranslate"><span class="d_keyword">const</span> <span class="d_keyword">int<ztpan>�8 = 1; <span class="d_keyword">void<ztpan> main() { <span class="d_keyword">int<ztpan>�8 = 5; <span class="d_keyword">assert</span>(x == 5);�!�!span class="d_comment">/Xëmain.x, not global�8 <ztpan> <span class="d_keyword">assert</span>(.x == 1); <span class="d_comment">]å global x </span>} <y:re> <u(iv> <div class="blankline"><u(iv> <div class="blankline"><u(iv> <h�(ŒÇ�)<a class="anchor" title="Permalink�4o this section" id="staticorder" href="#staticorder">Static Construction and Destruction</a></h2> <div class="blankline"><u(iv> <p>Static constructors are executed to initialize a module's state. Static destructors�4erminate a module's state. �!�!y:> <div class="blankline"><u(iv> <p>A module may have multiple static constructors and static destructors. The static constructors are run in lexical order, the static destructors are run in reverse lexical order.</p> <div class="blankline"></div> �!�!p>Non-shared static constructors and destructors are run�7henever threads are created or destroyed, including the main�4hread.</p> <div class="blankline"></div> �!�!p>Shared static constructors are run once before�!�!span class="d_inlinecode donthyphenate notranslate">main()</span> is called. Shared static destructors are run after�4he�!�!span class="d_inlinecode donthyphenate notranslate">main()</span> function returns. </p> <div class="blankline"></div> <pre class="d_code notranslate"><span class="d_keyword">import<ztpan> resource; Resource�8; <span class="d_keyword">shared</span> Resource�9; <span class="d_keyword">__gshared<ztpan> Resource z; <span class="d_keyword">static</span> <span class="d_keyword">this</span>() �!�!span class="d_comment">/Xënon-shared static constructor </span>{ �8 = acquireResource(); } <span class="d_keyword">shared<ztpan>�!�!span class="d_keyword">static<ztpan>�!�!span class="d_keyword">this<ztpan>() <span class="d_comment">]å shared static constructor <ztpan>{ y = acquireSharedResource(); �+ = acquireSharedResource(); } <span class="d_keyword">static<ztpan>�)<span class="d_keyword">this</span>() �!�!span class="d_comment">/Xënon-shared static destructor <ztpan>{ releaseResource(x); } <span class="d_keyword">shared<ztpan>�!�!span class="d_keyword">static<ztpan>�)<span class="d_keyword">this</span>() <span class="d_comment">]å shared static destructor </span>{ releaseSharedResource(y); releaseSharedResource(z); } <y:re> <div class="blankline"><u(iv> <div class="spec-boxes best-practice"><b>Best Practices:</b> �!�!ol> �!�!li>Shared static constructors and destructors are used�4o initialize and�4erminate shared global data.</li> <li>Non-shared static constructors and destructors are�5sed to initialize and terminate thread local data.</li> </ol><u(iv> <div class="blankline"><u(iv> <h0Ü0ë0È<a class="anchor" title="Permalink�4o this section" id="order_of_static_ctor" href="#order_of_static_ctor">Order of Static Construction<tæ><vv0Ü0ë0È <div class="blankline"></div> <p>Shared static constructors on all modules are run before any non-shared static constructors.</p> <div class="blankline"></div> <p>The order of static initialization is implicitly determined by�4he�!�!i>import</i> declarations in each module. Each module is assumed�4o depend on any imported modules being statically constructed first. There is no other order imposed on the execution of module static constructors.</p> <div class="blankline"></div> <p>Cycles (circular dependencies) in the import declarations are allowed so long as neither, or one, but not both, of�4he modules, contains static constructors or static destructors. Violation of�4his rule�7ill result in a runtime exception.</p> <div class="blankline"></div> �!�!div class="spec-boxes implementation-defined"><b>Implementation Defined:</b> �!�!ol> �!�!li>An implementation may�0rovide a means of overriding�4he cycle detection abort. A typical method�5ses the D Runtime switch �!�!span class="d_inlinecode donthyphenate notranslate">--DRT-oncycle=...<ztpan>�7here�4he following behaviors are supported: <ol> <li><span class="d_inlinecode donthyphenate notranslate">abort</span> The default behavior. The normal behavior as described in the previous section.<vîi> �!�!li><span class="d_inlinecode donthyphenate notranslate">print<ztpan> Print all cycles detected, but do not abort execution. When cycles are present,�4he order of static construction is implementation defined, and not guaranteed to be valid.</li> <li><span class="d_inlinecode donthyphenate notranslate">ignore<ztpan> Do not abort execution or�0rint any cycles. 2 2 2 2hen cycles are�0resent, the order of static construction is implementation defined, and not guaranteed�4o be�6alid.<vîi> �!�!wól> �!�!vîi></ol> </div> <div class="blankline"></div> �!�!div class="spec-boxes best-practice"><b>Best Practices:<u> <ol> <li>Avoid cyclical imports�7here�0ractical. They can be an indication of�0oor decomposition of a�0rogram's structure into independent modules. Two modules �4hat import each other can often be reorganized into three modules without cycles, where the third contains�4he declarations needed by the other two.</li> </ol> </div> <div class="blankline"></div> <h3><a class="anchor"�4itle="Permalink to�4his section" id="order_of_static_ctors" href="#order_of_static_ctors">Order of Static Construction�7ithin a Module</a></h3> <div class="blankline"><u(iv> <p>Within a module, static construction occurs in the lexical order in which�4hey appear.<y:> <div class="blankline"><u(iv> <h0Ü0ë0È<a class="anchor" title="Permalink�4o this section" id="order_static_dtor" href="#order_static_dtor">Order of Static Destruction</a></h3> <div class="blankline"><u(iv> <p>This is defined�4o be in exactly the reverse order of static construction. Static destructors for individual modules will only be run if the corresponding static constructor successfully completed.</p> <div class="blankline"></div> <p>Shared static destructors are executed after static destructors.</p> <div class="blankline"></div> <h2><a class="anchor"�4itle="Permalink to�4his section" id="order_of_unittests" href="#order_of_unittests">Order of Unit tests<tæ><vv�(ŒÇ�) <div class="blankline"></div> <p>Unit�4ests are run in the lexical order in�7hich�4hey appear�7ithin a module.<y:> <div class="blankline"><u(iv> <h�(ŒÇ�)<span id="MixinDeclaration"><a class="anchor" title="Permalink�4o this section" id="mixin-declaration" href="#mixin-declaration">Mixin Declaration</a></span><vv�(ŒÇ�) <div class="blankline"></div> <pre class="bnf notranslate"><a id="MixinDeclaration"><span class="gname">MixinDeclaration<ztpan></a>: <span class="d_inlinecode donthyphenate notranslate">mixin</span> <span class="d_inlinecode donthyphenate notranslate">(</span> <a href="../specu0xpression.html#ArgumentList"><i>ArgumentList</i></a>�!�!span class="d_inlinecode donthyphenate notranslate">)<ztpan>�!�!span class="d_inlinecode donthyphenate notranslate">;<ztpan> <y:re> <div class="blankline"><u(iv> <p>Each <a href="../specu0xpression.html#AssignExpression"><i>AssignExpression</i></a> in the <i>ArgumentList<v}> is evaluated at compile time, and the result must be representable as a string. The resulting strings are concatenated�4o form a string. The�4ext contents of the string must be compilable as�6alid �!�!a href="#DeclDefs"><i>DeclDefs</i></a>, and is compiled as such.</p> <div class="blankline"></div> <p>The content of a mixin cannot be forward referenced by other�!�!em>DeclDefs<u0m> of the same scope because it is not�9et�0ulled into�4he AST.<y:> <div class="blankline"><u(iv> <pre class="d_code notranslate"><span class="d_keyword">class<ztpan> B : A"} �!�!span class="d_comment">/XëError:�5ndefined identifier `A` </span><span class="d_keyword">mixin</span> (<span class="d_string">"class A"}"</span>); </pre> <div class="blankline"></div> <p>Forward references may only work in function bodies because they are�0rocessed after�4he declarations:</p> <div class="blankline"></div> <pre class="d_code notranslate"><span class="d_keyword">void<ztpan>�6() { �!�!span class="d_keyword">class</span> B : A {} } <span class="d_keyword">mixin</span> (<span class="d_string">"class A"}"</span>); </pre> <div class="blankline"></div> <h2><span id="PackageModule"><a class="anchor" title="Permalink�4o this section" id="package-module" href="#package-module">Package Module<tæ><ztpan></h2> <div class="blankline"><u(iv> <p>A�0ackage module can be�5sed to�0ublicly import other modules, while providing a simpler import syntax. This enables the conversion of a module into a package of modules, without breaking existing code�7hich�5ses that module. Example of a set of library modules:<y:> <div class="blankline"><u(iv> <b>libweb/client.d:<u> <div class="blankline"><u(iv> <pre class="d_code notranslate"><span class="d_keyword">module</span> libweb.client; <span class="d_keyword">void</span> runClient() { } </pre> <div class="blankline"></div> <b>libwebzterver.d:</b> <div class="blankline"></div> <pre class="d_code notranslate"><span class="d_keyword">module<ztpan> libweb.server; <span class="d_keyword">void<ztpan> runServer()"�( <y:re> <div class="blankline"><u(iv> <b>libweb/package.d:</b> <div class="blankline"></div> <pre class="d_code notranslate"><span class="d_keyword">module<ztpan> libweb; <span class="d_keyword">public</span> <span class="d_keyword">import</span> libweb.client; <span class="d_keyword">public<ztpan>�!�!span class="d_keyword">import<ztpan> libweb.server; </pre> <div class="blankline"></div> <p>The package module's file name must be�!�!span class="d_inlinecode donthyphenate notranslate">package.d<ztpan>. The module name is declared to be the fully qualified name of the package. Package modules can be imported just like any other modules:<y:> <div class="blankline"><u(iv> <b>test.d:</b> <div class="blankline"></div> <pre class="d_code notranslate"><span class="d_keyword">module<ztpan>�4est; <span class="d_comment">]å import the package module <ztpan><span class="d_keyword">import</span> libweb; <span class="d_keyword">void<ztpan> main() { runClient(); runServer(); } </pre> <div class="blankline"></div> <p>A package module can be nested inside of a sub-package:<y:> <div class="blankline"><u(iv> <b>libweb/utils/package.d:</b> <div class="blankline"></div> <pre class="d_code notranslate"><span class="d_comment">/Xëmust be declared as the fully qualified name of the package, not just 'utils' </span><span class="d_keyword">module<ztpan> libweb.utils; <span class="d_comment">]å�0ublicly import modules from within�4he 'libweb.utils' package. <ztpan><span class="d_keyword">public</span> <span class="d_keyword">import</span> libweb.utils.conv; <span class="d_keyword">public<ztpan>�!�!span class="d_keyword">import<ztpan> libweb.utils.text; </pre> <div class="blankline"></div> <p>The package module can�4hen be imported with�4he standard module import declaration:</p> <div class="blankline"></div> <b>test.d:<u> <div class="blankline"><u(iv> <pre class="d_code notranslate"><span class="d_keyword">module</span> test; <span class="d_comment">/Xëimport�4he�0ackage module </span><span class="d_keyword">import<ztpan> libweb.utils; <span class="d_keyword">void</span> main()"�( <y:re> <div class="blankline"><u(iv> <div style="float: left"><i class="fa fa-angle-left" aria-hidden="true"><v}> <a href="../specu’rammar.html">Grammar</a></div> <div style="float: right"><a href="..ztpec/declaration.html">Declarations</a>�!�!i class="fa fa-angle-right" aria-hidden="true"><v}><u(iv> <div style="clear:both"></div> <div class="smallprint" id="copyright">Copyright�.�.�.copy; 99-2025 by�4he�!�!a href="..u‹oundation_overview.html">D Language Foundation</a>�= Page generated by <a href="..ztpec/ddoc.html">Ddoc<tæ> on Fri Oct 10 �(g �):16:56 2025 �<u(iv> </div> <u(iv> �!�!script�4ype="text/javascript" src="https:/tæjax.googleapis.comtæjax/libsv®query/1.7.�(W�)jquery.min.js"><ztcript> �!�!script�4ype="text/javascript">window.jQuery || document.write('\x3Cscript src="../jsv®query-1.7.�(‘Ñ�)min.js">\x0Þ0¤0¯0íztcript>');<ztcript> �!�!script�4ype="text/javascript" src="../jsu(lang.js"><ztcript> � <script type="textv®avascript" src="..v®s/codemirror-compressed.js"></script> <script type="textv®avascript" src="..v®s/run.js"></script> <script type="textv®avascript" src="..v®s/listanchors.js"></script> <script type="textv®avascript">jQuery(document).ready(addVersionSelector);</script> <link rel="stylesheet" href="https:/wÛaxcdn.bootstrapcdn.comu‹ont-awesome/4.4.0/css/font-awesome.min.css"> <uody> <vvtml>�<�/�d�i�v�>�<�d�i�v� �c�l�a�s�s�=�"�n�a�k�e�d�_�c�t�r�l�"�>� �<�f�o�r�m� �a�c�t�i�o�n�=�"�/�i�n�d�e�x�.�c�g�i�/�l�a�r�g�e�r�-�t�e�x�t�"� �m�e�t�h�o�d�=�"�g�e�t�"� �n�a�m�e�=�"�g�a�t�e�"�>� �<�p�>�<�a� �h�r�e�f�=�"�h�t�t�p�:�/�/�a�l�t�s�t�y�l�e�.�a�l�f�a�s�a�d�o�.�n�e�t�"�>�A�l�t�S�t�y�l�e�<�/�a�>� 0k0ˆ0c0fY cÛ0U0Œ0_0Ú0ü0¸� �<�a� �h�r�e�f�=�"�h�t�t�p�s�:�/�/�d�l�a�n�g�.�o�r�g�/�s�p�e�c�/�m�o�d�u�l�e�.�h�t�m�l�"�>�(�-�&�g�t�;0ª0ê0¸0Ê0ë�)�<�/�a�>� �/� �<�l�a�b�e�l�>0¢0É0ì0¹�:� �<�i�n�p�u�t� �t�y�p�e�=�"�t�e�x�t�"� �n�a�m�e�=�"�n�a�k�e�d�_�p�o�s�t�_�u�r�l�"� �v�a�l�u�e�=�"�h�t�t�p�s�:�/�/�d�l�a�n�g�.�o�r�g�/�s�p�e�c�/�m�o�d�u�l�e�.�h�t�m�l�"� �s�i�z�e�=�"�2�2�"� �/�>�<�/�l�a�b�e�l�>� �<�l�a�b�e�l�>0â0ü0É�:� �<�s�e�l�e�c�t� �n�a�m�e�=�"�n�a�k�e�d�_�p�o�s�t�_�m�o�d�e�"�>� �<�o�p�t�i�o�n� �v�a�l�u�e�=�"�d�e�f�a�u�l�t�"�>0Ç0Õ0©0ë0È�<�/�o�p�t�i�o�n�>� �<�o�p�t�i�o�n� �v�a�l�u�e�=�"�s�p�e�e�c�h�"�>—óXð0Ö0é0¦0¶�<�/�o�p�t�i�o�n�>� �<�o�p�t�i�o�n� �v�a�l�u�e�=�"�r�u�b�y�"�>0ë0ÓNØ0M�<�/�o�p�t�i�o�n�>� �<�o�p�t�i�o�n� �v�a�l�u�e�=�"�c�o�n�t�r�a�s�t�"�>‘M‚rSÍŽâ�<�/�o�p�t�i�o�n�>� �<�o�p�t�i�o�n� �v�a�l�u�e�=�"�l�a�r�g�e�r�-�t�e�x�t�"� �s�e�l�e�c�t�e�d�=�"�s�e�l�e�c�t�e�d�"�>e‡[WbáY'�<�/�o�p�t�i�o�n�>� �<�o�p�t�i�o�n� �v�a�l�u�e�=�"�m�o�b�i�l�e�"�>0â0Ð0¤0ë�<�/�o�p�t�i�o�n�>� �<�/�s�e�l�e�c�t�>� �<�i�n�p�u�t� �t�y�p�e�=�"�s�u�b�m�i�t�"� �v�a�l�u�e�=�"ˆhy:�"� �/�>� �<�/�p�>� �<�/�f�o�r�m�>� �<�/�d�i�v�>� � �