@@ -940,11 +940,54 @@ fn foo(x: int) -> int {
940
940
There are some additional ways to define functions, but they involve features
941
941
that we haven't learned about yet, so let's just leave it at that for now.
942
942
943
+
943
944
## Comments
944
945
945
- return
946
+ Now that we have some functions, it's a good idea to learn about comments.
947
+ Comments are notes that you leave to other programmers to help explain things
948
+ about your code. The compiler mostly ignores them.
949
+
950
+ Rust has two kinds of comments that you should care about: ** line comment** s
951
+ and ** doc comment** s.
952
+
953
+ ``` {rust}
954
+ // Line comments are anything after '//' and extend to the end of the line.
955
+
956
+ let x = 5i; // this is also a line comment.
957
+
958
+ // If you have a long explanation for something, you can put line comments next
959
+ // to each other. Put a space between the // and your comment so that it's
960
+ // more readable.
961
+ ```
962
+
963
+ The other kind of comment is a doc comment. Doc comments use ` /// ` instead of
964
+ ` // ` , and support Markdown notation inside:
965
+
966
+ ``` {rust}
967
+ /// `hello` is a function that prints a greeting that is personalized based on
968
+ /// the name given.
969
+ ///
970
+ /// # Arguments
971
+ ///
972
+ /// * `name` - The name of the person you'd like to greet.
973
+ ///
974
+ /// # Example
975
+ ///
976
+ /// ```rust
977
+ /// let name = "Steve";
978
+ /// hello(name); // prints "Hello, Steve!"
979
+ /// ```
980
+ fn hello(name: &str) {
981
+ println!("Hello, {}!", name);
982
+ }
983
+ ```
984
+
985
+ When writing doc comments, adding sections for any arguments, return values,
986
+ and providing some examples of usage is very, very helpful.
946
987
947
- comments
988
+ You can use the ` rustdoc ` tool to generate HTML documentation from these doc
989
+ comments. We will talk more about ` rustdoc ` when we get to modules, as
990
+ generally, you want to export documentation for a full module.
948
991
949
992
## Compound Data Types
950
993
0 commit comments