Paths for Referring to an Item in the Module Tree - The Rust Programming Language
To show Rust where to find an item in a module tree, we use a path in the same way we use a path when navigating a filesystem. To call a function, we need to know its path. A path can take two forms: Both absolute and relative paths are followed by one or more identifiers separated by double colons (::). Returning to Listing 7-1, say we want to call the add_to_waitlist function. This is the same as asking: what’s the path of the add_to_waitlist function? Listing 7-3 contains Listing 7-1 with some of the modules and functions removed. We’ll show two ways to call the add_to_waitlist function from a new function eat_at_restaurant defined in the crate root. These paths are correct, but there’s another problem remaining that will prevent this example from compiling as-is. We’ll explain why in a bit. The eat_at_restaurant function is part of our library crate’s public API, so we mark it with the pub keyword. In the “Exposing Paths with the pub Keyword” section, we’ll go into more detail abou
Paths for Referring to an Item in the Module Tree - The Rust Programming Language 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 Auto Light Rust Coal Navy Ayu The Rust Programming Language Paths for Referring to an Item in the Module Tree To show Rust where to find an item in a module tree, we use a path in the same way we use a path when navigating a filesystem. To call a function, we need to know its path. A path can take two forms: An absolute path is the full path starting from a crate ro
Explore this link on the map →saved by
related reading
- Control Scope and Privacy with Modules - The Rust Programming Languagedoc.rust-lang.org
- Bringing Paths Into Scope with the use Keyword - The Rust Programming Languagedoc.rust-lang.org
- References and Borrowing - The Rust Programming Languagedoc.rust-lang.org
- Defining an Enum - The Rust Programming Languagedoc.rust-lang.org
- The Slice Type - The Rust Programming Languagedoc.rust-lang.org
- A half-hour to learn Rustfasterthanli.me
- Rust Language Cheat Sheetcheats.rs
- Methods - The Rust Programming Languagedoc.rust-lang.org
- Modular Errors in Rust - Sabrina Jewsonsabrinajewson.org
- Macros - The Rust Programming Languageweb.mit.edu
- An Example Program Using Structs - The Rust Programming Languagedoc.rust-lang.org
- Shared modules / The $lib alias • Svelte Tutoriallearn.svelte.dev