In this recipe, we created a sample library and made a .rlib extension package of the code. This will help us call the units of the library in other crates or Rust programs.
We created two public functions named public_function and indirect_access and a private function named private_function. We called private_function from indirect_access, which is a way through which we can call it outside the scope. Then, we created the library using the Rust compiler and passed a few command-line arguments to it, which tells the compiler to create the library format of the script.
While compiling the program, we ran rustc --crate-type=lib sample_lib.rs, which created a package named libsample_lib.rlib in the same directory. This file can be externally used at other crates. Alternatively, we can use Cargo to ship libraries by adding the [lib] tag in the Cargo.toml file.