Merge pull request #701 from kubo39/saturating_sub

Use `saturating_sub` instead of `checked_sub.unwrap_or`
This commit is contained in:
Corey Farwell 2018-06-27 07:40:20 -04:00 committed by GitHub
commit 953d3821b6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 2 additions and 2 deletions

View File

@ -122,7 +122,7 @@ fn parse_include_path(path: &str) -> LinkType<'static> {
let start = parts
.next()
.and_then(|s| s.parse::<usize>().ok())
.map(|val| val.checked_sub(1).unwrap_or(0));
.map(|val| val.saturating_sub(1));
let end = parts.next();
let has_end = end.is_some();
let end = end.and_then(|s| s.parse::<usize>().ok());

View File

@ -50,7 +50,7 @@ pub fn take_lines<R: RangeArgument<usize>>(s: &str, range: R) -> String {
let start = *range.start().unwrap_or(&0);
let mut lines = s.lines().skip(start);
match range.end() {
Some(&end) => lines.take(end.checked_sub(start).unwrap_or(0)).join("\n"),
Some(&end) => lines.take(end.saturating_sub(start)).join("\n"),
None => lines.join("\n"),
}
}