Python's help function

In python I could read docstring of a module with help(), How can I read help of a module in Rust?
I need to read other functions and variable of a module.

Running cargo doc --open will bring up the documentation for your project in a web browser.

If I need to rust's doc, Not my module, How do I it?

The easiest way is to use the online documentation:

https://doc.rust-lang.org/stable/std/index.html

3 Likes

There's no single source of documentation for Rust. There is separate language reference, the standard library documentation and a bunch of tutorial-like docs, beginning with the Rust book. What are you trying to find, exactly?

3 Likes

Python's help() is runtime: you can read the documentation while the program is running, because Python is a scripting interpreted language.

Rust is compiled, thus such a function would require to include all the documentation in the compiled binary (which is not the case). Maybe there is a macro for that...

Are you searching for a runtime access to the doc or just for the doc itself? (if the latter, the answer is in the previous messages)

3 Likes

Your approach to learning Rust seems to be repeatedly asking questions of the form "I can do thing X in Python, how can I do exactly the same thing X in Rust?". That is not going to be very productive, because Rust and Python are drastically different languages. Rust is basically the anti-thesis of everything Python has to offer.

Rust prefers compile-time verification, guaranteed safety, lack of runtime errors, static constructs over dynamic ones, and high runtime performance in exchange for slower compilation times. Rust is a language designed for writing large-scale, reliable, production-ready, mission critical software systems.

Python, on the other hand, favors developer convenience, easy access to a REPL, fast prototyping, and dynamic access to literally almost every aspect of the language. In exchange, it is very hard to write big, mission-critical, guaranteed-correct software systems in Python, and interpreting a Python program is several orders of magnitude slower than running an optimized Rust executable.

If you know Python, it won't help you much in internalizing the essence of Rust. Okay, both languages have functions and if statements and integers and strings and arrays and modules and documentation. But just about every language has these nowadays, so these are not the interesting part of Rust. In order to be productive in Rust, you will need to give up the mindset of transliterating code or concepts in a one-to-one manner from other languages.

If you are just getting started with Rust, please, read the book, which has been linked to above. Trying to replicate functions from other, radically different languages won't get you far, and you will only end up wasting your own time as well as other people's time, because nobody will be able to give you a real "solution" to such problems. We will only be able to parrot that "this and this Python function has no direct equivalent in Rust", and that is no good use of anyone's time.

6 Likes

Theirs also the rustup doc command.

1 Like

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.