Search code examples
rustdefinition

What is an "item" in Rust?


The Rust Book makes several references to the word "item", which confers the word a technical meaning in the context of the Rust programming language. For example, see Chapter 07-03:

The way privacy works in Rust is that all items (functions, methods, structs, enums, modules, and constants) are private by default. Items in a parent module can’t use the private items inside child modules, but items in child modules can use the items in their ancestor modules.

What is an item and is there a comprehensive list of all the kinds that there are in Rust?


Solution

  • Items - Rust Reference:

    An item is a component of a crate. [...] There are several kinds of items:

    • Modules
    • extern crate declarations
    • use declarations
    • Function definitions
    • Type definitions
    • Struct definitions
    • Enumeration definitions
    • Union definitions
    • Constant items
    • Static items
    • Trait definitions
    • Implementations
    • extern blocks