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"), } }