Skip to content

Even or odd and factorial

Pre-release
Pre-release

Choose a tag to compare

@frehburg frehburg released this 15 Oct 21:19
· 6 commits to main since this release

In this session I learned:

  • how to structure a rust project and use mod.rs files
  • how to write functions and return values
  • I got a lot of warnings from dead code/ unused imports, so I learned how to disable them
  • I learned how to work with Result
    • learned how to do error handling
    • unwrap()
    • to create a string from "text" by using .to_string()
    • How to use Ok() and Err
    • I used the ? operator for concise error handling
  • How to do unit testing
    • set up structure for unit tests
    • #[cfg(test)] and #[test] to execute tests
    • had some problems when trying to import from my code since I use this code structure:
      image
    • But was eventually able to fix it with lib.rs file -> also had to make mods and fns public
    • Learned about using public scopes pub(scope)
    • Learned to use assert_eq! and assert!

... by implementing a method that checks if an integer is even or odd and a method that calculates the factorial of a non-negative integer smaller than 21 (i64 bounds)

Next things to learn:

  • documentation: method/ class comments
  • structs
  • What the ! means exactly
  • ...?