From b349bfe64da8ea0f2ba3cb9eb1056a8f86a5e4a2 Mon Sep 17 00:00:00 2001 From: Marc Addeo Date: Sat, 5 Oct 2019 10:28:29 -0400 Subject: [PATCH] Improve code quality Simplified the changeset work and ran cargo fmt --- src/changelog.rs | 46 ++++++++-------------------------------------- src/main.rs | 4 +++- 2 files changed, 11 insertions(+), 39 deletions(-) diff --git a/src/changelog.rs b/src/changelog.rs index 5895e83..4bd3392 100644 --- a/src/changelog.rs +++ b/src/changelog.rs @@ -2,9 +2,9 @@ use chrono::NaiveDate; use derive_builder::Builder; use failure::Fail; use fstrings::*; +use indexmap::indexmap; use semver::Version; use serde_derive::{Deserialize, Serialize}; -use indexmap::indexmap; use std::fmt; #[derive(Debug, Clone, PartialEq, Serialize, Deserialize)] @@ -107,7 +107,7 @@ impl fmt::Display for Release { } // Release changes. - let mut changesets = indexmap!{ + let mut changesets = indexmap! { "Added" => Vec::new(), "Changed" => Vec::new(), "Deprecated" => Vec::new(), @@ -116,42 +116,12 @@ impl fmt::Display for Release { "Security" => Vec::new(), }; self.changes.iter().for_each(|change| match change { - Added(_) => match changesets.get_mut("Added") { - Some(changes) => changes.push(change), - None => { - changesets.insert("Added", vec![change]); - } - }, - Changed(_) => match changesets.get_mut("Changed") { - Some(changes) => changes.push(change), - None => { - changesets.insert("Changed", vec![change]); - } - }, - Deprecated(_) => match changesets.get_mut("Deprecated") { - Some(changes) => changes.push(change), - None => { - changesets.insert("Deprecated", vec![change]); - } - }, - Removed(_) => match changesets.get_mut("Removed") { - Some(changes) => changes.push(change), - None => { - changesets.insert("Removed", vec![change]); - } - }, - Fixed(_) => match changesets.get_mut("Fixed") { - Some(changes) => changes.push(change), - None => { - changesets.insert("Fixed", vec![change]); - } - }, - Security(_) => match changesets.get_mut("Security") { - Some(changes) => changes.push(change), - None => { - changesets.insert("Security", vec![change]); - } - }, + Added(_) => changesets.get_mut("Added").unwrap().push(change), + Changed(_) => changesets.get_mut("Changed").unwrap().push(change), + Deprecated(_) => changesets.get_mut("Deprecated").unwrap().push(change), + Removed(_) => changesets.get_mut("Removed").unwrap().push(change), + Fixed(_) => changesets.get_mut("Fixed").unwrap().push(change), + Security(_) => changesets.get_mut("Security").unwrap().push(change), }); changesets = changesets diff --git a/src/main.rs b/src/main.rs index 5249c2c..3a5ab18 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,4 +1,6 @@ -use clap::{app_from_crate, crate_authors, crate_description, crate_name, crate_version, AppSettings, Arg}; +use clap::{ + app_from_crate, crate_authors, crate_description, crate_name, crate_version, AppSettings, Arg, +}; use clparse::ChangelogParser; use failure::Error; use std::io::{self, Read};