Skip to content
← All Rust tracks

Modules, Visibility, Testing and Docs

Rust

Organize code into modules, choose public interfaces, and write tests and documentation that help callers use your code correctly.

This track uses Rust. You can make it your practice mode to browse related content across the site.

17 exercises

5 articles

Explore freely. Sign in to keep your progress.

Your learning sequence

  1. 1 Not solved yet. Build a module tree and inspect its paths Practice · Easy
  2. 2 Not solved yet. Paths: absolute, relative, crate::, self::, super:: Practice · Easy
  3. 3 Not solved yet. Expose a small module API Practice · Easy
  4. 4 Not solved yet. Restricted visibility: pub(crate), pub(super), pub(in path) Practice · Medium
  5. 5 Not solved yet. use declarations: nested groups, as, self, and _ Practice · Medium
  6. 6 Not solved yet. Resolve names in a simplified import model Practice · Medium
  7. 7 Not solved yet. Three namespaces: types, values, and macros Practice · Medium
  8. 8 Not solved yet. Model public item paths and re-exports Practice · Hard
  9. 9 Not solved yet. The five preludes Practice · Medium
  10. 10 Not solved yet. macro_rules! scoping is not item scoping Practice · Hard
  11. 11 Not solved yet. Module file layout: foo.rs, foo/mod.rs, and #[path] Practice · Medium
  12. 12 Not solved yet. Conditional compilation with cfg and cfg_select! Practice · Medium
  13. 13 Crate vs package vs workspace vs module Read
  14. 14 Cargo.toml essentials Read
  15. 15 Not solved yet. Version requirements: caret, tilde, wildcard, pre-releases Practice · Medium
  16. 16 Not solved yet. Cargo features and the additivity rule Practice · Hard
  17. 17 Not solved yet. SemVer for Rust APIs: what actually breaks Practice · Hard
  18. 18 Workspaces, publishing, MSRV and docs.rs Read
  19. 19 #[test], the assert macros, and what a test actually is Read
  20. 20 Not solved yet. Build a test runner that catches panics Practice · Hard
  21. 21 Unit tests, #[cfg(test)], integration tests and the lib+bin split Read
  22. 22 Not solved yet. Test selection: filters, #[ignore], and the libtest CLI Practice · Medium

Check yourself

4 questions · not saved while you're signed out

Use these questions to check your understanding and compare explanations. Your score does not affect track completion.

0 / 4 correct

With Cargo's default test discovery, why can tests/api.rs call double but not private_helper?

Choose one answer to reveal the explanations. Answers are kept only while this page is open.

// src/lib.rs
fn private_helper(x: i32) -> i32 {
    x * 2
}

pub fn double(x: i32) -> i32 {
    private_helper(x)
}

// tests/api.rs (a separate file; the library crate is named my_crate)
#[test]
fn doubles_a_value() {
    assert_eq!(my_crate::double(21), 42);
}
Question 1 of 4