Skip to content

Simplify control flow #16

@olivier-dj

Description

@olivier-dj

Use of options coupled with the current unwrapping strategy can render the code hard to follow. We should identify where guards could be more appropriate:

  fn main() {
      let option_1 = Some(42);
      let option_2 = Some(32);
      
      // with if..
      if let Some(val_1) =option_1 {
          if let Some(val_2) = option_2 {
              // 2-block depth
              println!("{val_1} {val_2}")
          }     
      }    
      // val_1 & val_2 leave scope...
  
      // Use guards instead
      let Some(val_1) = option_1 else { return };
      let Some(val_2) = option_2 else { return };
      
      // and values are still in the scope !
      println!("{val_1} {val_2}")
  }

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions