project_template/lib.rs
1//! This is a template crate for Rust project
2//! `//!` is a enclosing doc comment for the whole crate.
3
4pub mod sample_mod {
5 //! `//!` comment can be used for the module.
6
7 /// `///` is a doc comment for the function, struct, or
8 /// trait ...
9 pub fn public_fn_in_mod(arg: i64) {
10 // `//` comment is not a doc comment.
11 println!(
12 "called `sample_module::public_fn_in_module()`, arg: {}",
13 arg
14 );
15 }
16}
17
18/// This is a public function.
19pub fn public_function() {
20 println!("called `public_function()`");
21}
22
23/// This is a private function.
24/// and won't be shown in the documentation on docs.rs.
25#[allow(dead_code)]
26fn private_function() {
27 println!("called `private_function()`",);
28 println!(
29 "called `private_function()` `private_function()` `private_function` \
30 `private_function()` `private_function()` `private_function()` \
31 `private_function()`"
32 );
33}
34
35/// `pub` and `pub(crate)` is different.
36/// `pub` is visible in user code,
37/// `pub(crate)` is only visible in this crate.
38/// thus `pub(crate)` item won't be shown in https://docs.rs
39pub mod another_mod;
40pub(crate) mod sub_mod;
41
42#[cfg(test)]
43mod tests {
44 #[test]
45 fn it_works() {
46 assert_eq!(2 + 2, 4);
47 }
48
49 #[test]
50 fn access_to_child_mod() {
51 super::another_mod::pub_in_crate();
52 // super means the parent of `tests` module.
53
54 // super::sub_mod::another_mod::pub_in_super();
55 // compile error because another_mod is only public in
56 // sub_mod;
57 }
58}