Rust
Version
Running on Rust v1.79
Supported languages
Rust
Testing framework
Special reminders and implementation details
rs
#[cfg(test)]
use crate::HelloWorld::hello_world;
mod nested_tests {
use super::*;
#[test]
fn test_hello_world_not_empty() {
assert!(!hello_world().is_empty());
}
#[test]
fn test_hello_world_contains_hello() {
assert!(hello_world().contains("Hello"));
}
#[test]
fn test_hello_world_exact_length() {
assert_eq!(hello_world().len(), 13);
}
}
Included libraries
How to debug
In Rust, you can use the log crate to print debug information. This is flexible and powerful because you can control the log level and format.
Steps to Debug Using log::info! Statements
Identify the Problem Area: Locate the section of your code where you suspect the problem might be.
Insert
log::info!
Statements: Addlog::info!
statements before and after the suspected problematic code to print out variable values and flow control.Check the Results Output of your tests
Analyze the Output: Look at the values printed on the results console to understand what's going wrong in your code. Adjust your code based on the findings and repeat as necessary.
Here’s an example of how to use log::info!
for debugging:
rs
pub fn sum(a: i32, b: i32) -> i32 {
log::info!("Function called with arguments: {}, {}", a, b); // Log function call
let result = a + b;
log::info!("Sum after addition: {}", result); // Log sum calculation
result
}