Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Syntax
Item
    OuterAttribute* ( VisItem | MacroItem )

VisItem
    Visibility?
    (
        Module
      | ExternCrate
      | UseDeclaration
      | Function
      | TypeAlias
      | Struct
      | Enumeration
      | Union
      | ConstantItem
      | StaticItem
      | Trait
      | Implementation
      | ExternBlock
    )

MacroItem
      MacroInvocationSemi
    | MacroRulesDefinition

一个 是 crate 的一个组件。 项 在 crate 中通过一组嵌套的 模块 来组织。每个 crate 都有一个唯一的“最外层”匿名模块;crate 内的所有后续 项 在 crate 的模块树中都有 路径

项 完全在编译时确定,通常在执行期间保持固定,并可能驻留在只读内存中。

有几种类型的 项 :

项 可以在 crate 根部模块块表达式 中声明。

项 的一个子集,称为 关联项,可以在 特型实现 中声明。

项 的一个子集,称为外部项,可以在 extern 中声明。

项 可以按任何顺序定义,唯一的例外是 macro_rules,它有自己的作用域行为。

项 名称的 名称解析 允许在模块或块中引用该 项 的位置之前或之后定义它。

有关 项 的作用域规则,请参见 项作用域