From 289028850f196aa89b411095ee883206f56227f1 Mon Sep 17 00:00:00 2001 From: Hiroki Noda Date: Mon, 4 Jun 2018 01:42:09 +0900 Subject: [PATCH] Use `saturating_sub` instead of `checked_sub.unwrap_or` --- src/preprocess/links.rs | 2 +- src/utils/string.rs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/preprocess/links.rs b/src/preprocess/links.rs index fe0342b8..8b0c863a 100644 --- a/src/preprocess/links.rs +++ b/src/preprocess/links.rs @@ -122,7 +122,7 @@ fn parse_include_path(path: &str) -> LinkType<'static> { let start = parts .next() .and_then(|s| s.parse::().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::().ok()); diff --git a/src/utils/string.rs b/src/utils/string.rs index 22459093..9d9a614e 100644 --- a/src/utils/string.rs +++ b/src/utils/string.rs @@ -50,7 +50,7 @@ pub fn take_lines>(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"), } }