dtolnay/cargo-expand

Correct way of expanding once and get code for each file separately

fzyzcjy opened this issue · 0 comments

Hi, thanks for the wonderful tool!

When working on https://github.com/fzyzcjy/flutter_rust_bridge, cargo expand is used to expand user source code. Currently, only one call is made, and later the modules of corresponding files are extracted hackily.

However, it seems not very trivial to correctly extract what code belongs to a file (module). For example, if we simply count matching brackets, then we will fail when the code contains something like let a = "{"; because that bracket does not match.

Cargo expand does support expanding a single item, which works great. However, it seems that the time to expand that single item is the same as expanding a whole crate. Since flutter_rust_bridge needs to scan all files of the crate, it will call cargo expand (e.g.) hundreds of times, which is super slow, so this approach may not be super ideal.

Therefore, I would appreciate it if I could know how to run cargo-expand once, and then get code for each file(module) separately?