#cleaner match expression

4 messages · Page 1 of 1 (latest)

devout birch
#

maybe you should write two matches in sequence?

#
let level = opt_level(txt);
match level {
  OptLevel::Info => last_opt_level = OptLevel::Monitor,
  OptLevel::Warn => last_opt_level = OptLevel::Warn,
  OptLevel::Error => last_opt_level = OptLevel::Severe,
  OptLevel::Severe | OptLevel::Unknown => {},
}
match level {
  OptLevel::Info | OptLevel::Error => {},
  OptLevel::Monitor | OptLevel::Warn | OptLevel::Severe => {
    opt_lines.push(OptLines { level: last_opt_level, chunk: chunk.clone() });
    chunk = "".to_string();
    chunk.push_str(line);
  }
  OptLevel::Unknown => {
    chunk.push_str(format!("\t{}", line).as_str());
  }
}
#

something like that

#

where one of them is responsible for last_opt_level and one of them is responsible for the formatting