Advertisement
cwchen

[Rust] module demo

Aug 23rd, 2017
1,362
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Rust 0.37 KB | None | 0 0
  1. mod english {
  2.     pub fn hello(name: &str) {
  3.         println!("Hello, {}", name);
  4.     }
  5. }
  6.  
  7. mod chinese {
  8.     pub fn hello(name: &str) {
  9.         println!("你好,{}", name);
  10.     }
  11. }
  12.  
  13. fn main() {
  14.     // Call modules
  15.     use english;
  16.     use chinese;
  17.  
  18.     // Call two functions with the same name
  19.     english::hello("Michael");
  20.     chinese::hello("麥可");
  21. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement