I do really like having from ... import ..., but it seems most people don’t like it.
If I understand it right, we want to make universal paths which could be used in any context.
I’d suggest use the following:
Path related to the current module - just path, i.e., solve::Program
Path related to the current crate - a path starting with ::crate::, i.e., ::crate::a::solve::Program
Path related to the extern crate - a path starting with ::extern::crate::, i.e., ::extern::crate::std::io::Error
It can be used for use:
use solve::Program;
use ::crate::a::solve::Solver;
use ::extern::crate::std::io::Error;
It can be used in other contexts:
fn solve_program(program: solve::Program) -> ::extern::crate::std::io::Error {
::crate::a::solve::Solver.solve(program)
}
I understand that uses related to either the current crate or to an extern crate are verbose, but it is very easy to read and it makes clear distinction.
The only problem I can think of is that people might forget if they need to write :: or not.
Some people could try to write ::solve::Program or crate::std::io::Error.
The I can think of two solutions:
- Add
:: to path related to the current module like ::solve::Program and then it is consistent.
- Remove
:: from other paths like crate::a::solve::Solver and extern::crate::std::io::Error.
The first solution breaks all code written so it’s only for exhaustiveness.
I’m in favor of the second variant, but it requires us to forbid making modules with names extern and crate. I don’t know if it is allowed now.