O'Reilly logo

Rust Essentials by Ivo Balbaert

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Chapter 7. Organizing Code and Macros

We start this chapter by discussing the large-scale code-organizing structures in Rust, namely modules and crates. We will look at the following topics:

  • Building crates
  • Defining a module
  • Visibility of items
  • Importing modules and file hierarchy
  • Importing external crates
  • Exporting a public interface
  • Adding external crates to a project
  • The test module

We will also touch upon how to build macros in order to generate code and save time and effort, particularly in these topics:

  • The reason for using macros
  • Developing macros
  • Using macros from crates

Modules and crates

Until now, we only looked at the situation where our code fitted in one file. However, when a project evolves, we will want to split the code across several files, ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required