Rework a match to possibly be more understandable

This commit is contained in:
Carol (Nichols || Goulding) 2019-08-05 19:49:43 -04:00
parent 40159362c0
commit 8c4b292d58
No known key found for this signature in database
GPG Key ID: D04B39A6CA243902
1 changed files with 11 additions and 9 deletions

View File

@ -196,17 +196,19 @@ fn parse_include_path(path: &str) -> LinkType<'static> {
}; };
let end = parts.next(); let end = parts.next();
let has_end = end.is_some(); // If `end` is empty string or any other value that can't be parsed as a usize, treat this
let end = end.and_then(|s| s.parse::<usize>().ok()); // include as a range with only a start bound. However, if end isn't specified, include only
// the single line specified by `start`.
let end = end.map(|s| s.parse::<usize>());
match (start, end, has_end) { match (start, end) {
(Some(start), Some(end), _) => LinkType::IncludeRange(path, LineRange::from(start..end)), (Some(start), Some(Ok(end))) => LinkType::IncludeRange(path, LineRange::from(start..end)),
(Some(start), None, true) => LinkType::IncludeRange(path, LineRange::from(start..)), (Some(start), Some(Err(_))) => LinkType::IncludeRange(path, LineRange::from(start..)),
(Some(start), None, false) => { (Some(start), None) => LinkType::IncludeRange(path, LineRange::from(start..start + 1)),
LinkType::IncludeRange(path, LineRange::from(start..start + 1)) (None, Some(Ok(end))) => LinkType::IncludeRange(path, LineRange::from(..end)),
(None, None) | (None, Some(Err(_))) => {
LinkType::IncludeRange(path, LineRange::from(RangeFull))
} }
(None, Some(end), _) => LinkType::IncludeRange(path, LineRange::from(..end)),
(None, None, _) => LinkType::IncludeRange(path, LineRange::from(RangeFull)),
} }
} }