From 3b1dcca5d01ccb5f97a85174e0fc4a95c726ff5a Mon Sep 17 00:00:00 2001 From: Taylor Skinner Date: Mon, 4 Jun 2018 17:19:34 -0600 Subject: [PATCH] use map() --- src/app.rs | 21 ++++++++++----------- 1 file changed, 10 insertions(+), 11 deletions(-) diff --git a/src/app.rs b/src/app.rs index 54baa39f..43b209f0 100644 --- a/src/app.rs +++ b/src/app.rs @@ -282,7 +282,7 @@ impl App { term_width: Term::stdout().size().1 as usize, files, theme: self.matches.value_of("theme"), - line_range: LineRange::from(self.matches.value_of("line-range")), + line_range: self.matches.value_of("line-range").map(LineRange::from), }) } @@ -351,20 +351,19 @@ pub struct LineRange { } impl LineRange { - pub fn from(value: Option<&str>) -> Option { - match value { - None => None, - Some(range_raw) => { - return LineRange::parse_range(range_raw).ok(); - } + pub fn from(range_raw: &str) -> LineRange { + LineRange::parse_range(range_raw).unwrap_or(LineRange::new()) + } + + pub fn new() -> LineRange { + LineRange{ + lower: usize::min_value(), + upper: usize::max_value(), } } pub fn parse_range(range_raw: &str) -> Result { - let mut new_range = LineRange{ - lower: usize::min_value(), - upper: usize::max_value(), - }; + let mut new_range = LineRange::new(); if range_raw.bytes().nth(0).ok_or("No first byte")? == b':' { new_range.upper = range_raw[1..].parse()?;