zjp-CN / term-rustdoc

[WIP] A TUI for Rust docs that aims to improve the UX on tree view and generic code.
17 stars 1 forks source link

Recursive reexported module should stop when the inner module duplicates as ancestor module #3

Closed zjp-CN closed 7 months ago

zjp-CN commented 7 months ago

This is a follow-up to #2 .

Background

actix contains infinite recursive modules:

actix
├── [Mod] dev
│   └── [Mod] prelude (src code: pub use crate::dev)
│       └── [Mod] dev (this module duplicates as an ancestor module, leading to stack overflows)
└── [Mod] prelude
    └── [Mod] dev (src code: pub use crate::prelude::*)
        └── [Mod] prelude (this module duplicates as an ancestor module, leading to stack overflows)

The HTML rendering version show them as the source code does:

But the rendering is imperfect as tree view because a complete tree always is cached as known lines.

Even though the syntax of use actix::prelude::dev::prelude is acceptable in Rust and for human, it's definitely not encouraged to use. (Well, it might serve as an odd macro trick.)

So to solve the problem of stack overflows, there are several ways:

zjp-CN commented 7 months ago
├── [Mod] actix::prelude
│   ... (non-module items omitted under prelude module)
│   ├─➤ [Mod] actors
│   ├── [Mod] dev
│   ... (non-module items omitted under dev module)
│   │   ├─➤ [Mod] actix::dev::channel
│   │   └── [Mod] prelude
│   │       ├─➤ [Mod] actors
│   │       ├─➤ [Mod] fut
│   │       ╰─➤ [Mod] io
│   ├─➤ [Mod] fut
│   ╰─➤ [Mod] io

vs HTML version

//Module actix::prelude
pub use crate::actors;  
pub use crate::dev; 
pub use crate::fut; 
pub use crate::io;

//Module actix::dev
pub use crate::prelude::*;  
pub mod channel { ... }