See all impl fn type signatures w/o seeing body?

The typical function looks something like:

fn name(args) -> output { body }`

where we can call the name/args/output the signature of the function.

In C like languages, we have .h/.cpp separation, where one has the signature, and the other contains the body/implementation.

In Rust, on some classes with too many long functions, I'd like a way to only specify the type signature (a Table of Contents of sort), and then use jump-to-def to jump to the body/impl.

Is there any way to do this in Rust? One solution is to create a useless trait, where the trait body would contain just the signatures, and the "impl trait for ... " would contain the actual body; but this seems a bit silly.

I'd balk if I saw it used, but here's one way.

If you want to see the documentations of its public APIs, why don't you run cargo doc --open on it?


How about folding all the function bodies? Many editors and IDEs will let you do this, through the appropriate Rust plugin or rust-analyzer or whatever.

Navigation: I find easier to jump around in IntelliJ than in a web browser.
Editing: With IntelliJ, I can editor where the cursor is. With browser, I have to then find the corresponding location in IntelliJ.

Maybe you already know this, but in IntelliJ there are two ways to get all the types and functions in a file.

(The following shortcuts are based on my mac setup YMMV):

  1. Command + F12 :: brings up the "Main Menu -> Navigate -> File Structure" shortcut modal which has a list of top level constants, traits, and functions with instant type-to-search.

  2. Command + 7 :: Use the persistent version of (1) by bringing up the "Structure" view: "Top menu -> View -> Tool Windows -> Structure"

I wish there was similar functionality for the module / crate level but I don't think it exists yet.

This is pretty cool. I'm also using IdeaVIM. If there was only a way I could navigate this with vim keys "hjkl, /search" ... Ideally some hot key lets me swap between

  1. edit current file
  2. read only view of 'file' that represents this 'tool windows -> structure'

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.