1. 12
  1.  

  2. 5

    One rarely mentioned technique for dealing with errors: remove the possibility of the error at all.

    Using the article’s example

    // library
    pub fn count_words(lines: &mut dyn Iterator<Item = String>) -> u32 { 
        ...
    }
    
    // binary 
    fn main() {
        ...
        let mut err = Ok(());
        let mut iter = reader
            .lines()
            .map_while(|line| line.map_err(|it| err = Err(it)).ok());
        let wordcount = wordcount::count_words(&mut iter);
        err?;
        ...
    }
    
    1. 5

      Shout out to color_eyre, a fork of anyhow that colorizes backtraces.