O'Reilly logo

Mastering Rust by Vesa Kaihlavirta

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

Using other pieces of code in your module

A quick word about how to include code from other places into the module you are writing. Rust's module system has its own pecularities, but it's enough to note now that the use statement brings code from another module into the current namespace. It does not load external pieces of code, it merely changes the visibility of things:

// use.rs use std::ascii::AsciiExt; fn main() {   let lower_case_a = 'a';   let upper_case_a = lower_case_a.to_ascii_uppercase();   println!("{} upper cased is {}", lower_case_a, upper_case_a); } 

In this example, the AsciiExt module contains an implementation of the to_ascii_uppercase for the char type, so including that in this module makes it possible to use the method ...

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