What's happening is that when you try to import decoders::Decoders in image.rs, you need to go through the next level up, because using this:mod decodersuse decoders::Decoders表示decoders现在将是所有者"或在image下,这是不可能的,因为仅 lib.rs,mod.rs或main.rs文件可以在其他文件中具有模块.因此,要解决此问题,您可以将文件结构更改为此:Means that decoders will now be "owned" or under image, which is impossible since only lib.rs, mod.rs or main.rs files can have modules in other files. So, to fix this, you can either change your file structure to this:src main.rs image mod.rs decoder.rs或者,在main.rs中使用它:mod decoders;mod image;,并且在image.rs中是这样的:use super::decoders::Decoders;//Or alternativelyuse crate::decoders::Decoders;此外,要解决嵌套mod问题,请在decoders.rs中执行以下操作:Also, to fix your nested-mod problem, do the following in decoders.rs://Your code, no `mod Decoders`以及以下具有mod decoders语句的位置:and the following where you have your mod decoders statement:#[your_attribs]mod decoders; 这篇关于为什么不能从同一目录中的其他文件导入模块?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 上岸,阿里云!