Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 820
Paul Razvan Berg Avatar asked Dec 07 '20 17:12

Paul Razvan Berg


2 Answers

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
like image 122
Paul Razvan Berg Avatar answered Sep 28 '22 04:09

Paul Razvan Berg


An item is simply any declaration that could appear globally in a program or module, such as a fn, struct, or use.

Reference: Programming Rust: Fast, Safe Systems Development (2nd Edition)

like image 34
Yousuf Avatar answered Sep 28 '22 05:09

Yousuf