main/
main.rs

1use report::{Result, log, report, info, bail};
2use std::fs::File;
3use std::io::{BufRead, BufReader};
4
5#[report]
6#[log("Running experiments")]
7fn main() {
8    let path = "data.txt";
9    
10    #[report("Running task one on {path}")]
11    task_one(path).ok();
12
13    let path = "Cargo.toml";
14    #[report("Running task two on {path}")]
15    task_two(path).ok();
16}
17
18fn task_one(file: &str) -> Result {
19    let _file = File::open(file)?; 
20    bail!("File exists, even though it should not")
21}
22
23#[report]
24fn task_two(file: &str) -> Result {
25    let file = File::open(file)?;
26    let metadata = file.metadata()?;
27
28    info!("File size: {}", metadata.len());
29    
30    for line in BufReader::new(file).lines() {
31        #[report("Reading line")]
32        let line = line?;
33
34        if line.starts_with("[") {
35            info!("Found section: {line}");
36        }
37    }
38
39    Ok(())
40}