Item

See also: Reference – Items

An item is a syntax that is neither a statement nor an expression, and can appear in places where statements or expressions are illegal.

Different kinds of items

 * Functions
 * Types (structs, enums, unions, type aliases)
 * Traits
 * Impl Blocks (both inherent impls and trait impls)
 * Modules
 * Imports
 * Macros
 * Constants and static variables
 * External blocks
 * Associated items (these are only allowed in a trait,  block or   block)
 * Associated items (these are only allowed in a trait,  block or   block)

Where items can appear
Except for associated items, they can appear in any scope, including the global scope. Notably, they can appear within a function, for example:

Associated items (i.e. associated functions, types and constants) must appear in a, an   block or an   block.

Lang items
Lang items are attributes on items that are treated special by the compiler.

For example, the type is special in that it allows moving a value out of the box by dereferencing it. The type is special, because it provides interior mutability. The Sized trait is special, because it is implemented automatically (even though it is not an auto trait), and cannot be implemented manually. Here's the full list of lang items.

Declaring lang items
This part is relevant if you want to create your own version of the,   and/or   crates.

Lang items are a nightly-only feature and will never be stabilized. They're declared with the attribute:

Lang items are defined in the Rust compiler. It is not possible to define new lang items in Rust.

Note that we used the experimental attribute to remove the   crate from our dependencies. Otherwise, there would be two  lang items, but each lang item can only be declared once: