How and why does rust allow cyclic imports in modules?

54 points vikigenius 39 comments

I know that crates can't have cyclic dependencies. But it seems like modules can.

For ex: file1.rs can use file2.rs and file2.rs can also use file1.rs

But I have not seen this allowed in other languages I am familiar with. Python for example would complain about cyclic imports if you do something like this.

I saw this thread on golang Why does Go prevent cyclic imports?

And well the opinion seems to be that it introduces better practices.

There is also this thread: How bad is for usability to allow circular module dependencies

Is Rust rare in this? Why did they decide to allow this? What are the pros and cons of this in terms of usability and best practices etc.?