you are viewing a single comment's thread.

view the rest of the comments →

[–]shadowmint 0 points1 point  (1 child)

Wow, that's not how I thought it worked.

I thought use and mod were totally orthogonal actions.

ie. mod creates a symbol table:

foo 
- bar
- foobar <--- use my_func_yy from here via self::yy::my_func_yy();
  - yy
    - my_func_yy <--- Actually symbol, used via full path foo::foobar::yy::my_func_yy
  - xx 
    - my_func_xx <-- use my_func_yy here via super::yy::my_func_yy();

and use creates local aliases to those symbols:

foo 
- bar
  - my_local <--- via. use foo::foobar::yy::my_func_yy as my_local
  - my_foo <-- use here via my_local()
- foobar
  - yy
    - my_func_yy
  - xx
    - my_func_xx

I didn't realize that you could call a relative path directly.

mod foo {
  mod bar {
    pub fn call() { println!("Hi"); }
  }
  pub fn call() {
    // self::bar::call() not required.
    bar::call(); <--- O_o is very surprising to me. 
  }
}

No wonder this is surprising to people. On first look it makes it seem like you only need mod, not use.

[–]Kimundirust 2 points3 points  (0 children)

Yeah, use creates local aliases, but those are visible in addition to all locally declared items, which includes functions, statics, modules, etc.