I think you have indeed missed something. Adding use imported::Imported;
at the top of the file does work—I presume that this is not precisely what you tried to compile.
use
statements, although written before the mod
statements, are resolved after the mod, so there is no source order problem.
I presume that your error is in fact that your file imports.rs
was not the crate root. Remember that a use
statement takes an absolute path if you don't use super
or self
in it. To make it work in any place, you would need to write use self::imported::Imported;
; assuming you were compiling a lib.rs
containing mod imports;
, you would have needed to use imports::imported::Imported
, the absolute path to the trait.
(BTW, you can replace return x;
at the end of the function with just x
. Remember Rust's block value doctrine, whereby the last expression in a block is the value of the block.)