-1

I'm new to rust and am trying to find out more about functions, structs, methods, etc. as I work on a project with external crates. I'm reading the documentation as I go which is sufficient but slow, as I'm used to something similar to getting Information on a function etc. I see that there is debugging, but I was wondering what general methods are out there to finding information on structs methods etc. aside from 'read the manual' or 'look at compiler errors'

kana
  • 605
  • 7
  • 12
  • 4
    `cargo doc` will build a local copy of every crate doc used by your project. You can read it with any browser or with a some IDEs with Rust integration, such as VS-Code. – rodrigo Oct 25 '20 at 22:56

1 Answers1

1

Personally, I generally keep tabs to https://doc.rust-lang.org/std/index.html and https://docs.rs/ open. Of course, you likely have already considered those options.

As suggested by rodrigo@, you can run cargo doc --open to locally generate crate documentation for your project. The --open option will attempt to open the webpage for the documentaion in your preferred browser. (On macOS, this seems do work okay.) The webpage will be at something like <project-root>/target/doc/<project name>/ index.html.

Another alternative is to install rust-analyzer which will run an LSP server for Rust. This server can be integrated with many different IDEs or Editor to quickly show documentation or even jump to the implementation of a function. For example, I setup lsp-ui for Emacs a few weeks ago and have found the lsp-ui-doc-show and lsp-ui-peek-find-definitions to be very helpful for those purposes.

Hopefully some of this advice helps! =]

Aside: It's worth noting that Python and R are interpeted languages, and so have CLI-like environments where you can run something like a help function. Rust is however not an interpreted language, so you're not likely to find something very close to what you see in Python and R with respect to "help" functions.

  • FWIW if your search engine is duckduckgo it has bang patterns for many rust sites. `!rust ` will automatically look for the term on doc.rust-lang.org. `!docsrs` will search on docs.rs (but just the package names so less useful). – Masklinn Oct 26 '20 at 07:21