closedcaption: Use RangeBounds::contains() directly instead of our copy

It's stabilized since 1.35 and we require at least 1.39 nowadays.
This commit is contained in:
Sebastian Dröge 2019-12-14 11:12:18 +02:00
parent f638b0eef7
commit 23ed11e52f
2 changed files with 2 additions and 38 deletions

View file

@ -67,24 +67,6 @@ where
from_str(take_while1(|c: u8| c >= b'0' && c <= b'9').message("while parsing digits"))
}
/// Copy from std::ops::RangeBounds as it's not stabilized yet.
///
/// Checks if `item` is in the range `range`.
fn contains<R: std::ops::RangeBounds<U>, U>(range: &R, item: &U) -> bool
where
U: ?Sized + PartialOrd<U>,
{
(match range.start_bound() {
std::ops::Bound::Included(ref start) => *start <= item,
std::ops::Bound::Excluded(ref start) => *start < item,
std::ops::Bound::Unbounded => true,
}) && (match range.end_bound() {
std::ops::Bound::Included(ref end) => item <= *end,
std::ops::Bound::Excluded(ref end) => item < *end,
std::ops::Bound::Unbounded => true,
})
}
/// Parser for a run of decimal digits, that converts them into a `u32` and checks if the result is
/// in the allowed range.
fn digits_range<'a, I: 'a, R: std::ops::RangeBounds<u32>>(
@ -95,7 +77,7 @@ where
I::Error: ParseError<I::Item, I::Range, I::Position>,
{
digits().then(move |v| {
if contains(&range, &v) {
if range.contains(&v) {
value(v).left()
} else {
unexpected_any("digits out of range").right()

View file

@ -60,24 +60,6 @@ where
from_str(take_while1(|c: u8| c >= b'0' && c <= b'9').message("while parsing digits"))
}
/// Copy from std::ops::RangeBounds as it's not stabilized yet.
///
/// Checks if `item` is in the range `range`.
fn contains<R: std::ops::RangeBounds<U>, U>(range: &R, item: &U) -> bool
where
U: ?Sized + PartialOrd<U>,
{
(match range.start_bound() {
std::ops::Bound::Included(ref start) => *start <= item,
std::ops::Bound::Excluded(ref start) => *start < item,
std::ops::Bound::Unbounded => true,
}) && (match range.end_bound() {
std::ops::Bound::Included(ref end) => item <= *end,
std::ops::Bound::Excluded(ref end) => item < *end,
std::ops::Bound::Unbounded => true,
})
}
/// Parser for a run of decimal digits, that converts them into a `u32` and checks if the result is
/// in the allowed range.
fn digits_range<'a, I: 'a, R: std::ops::RangeBounds<u32>>(
@ -88,7 +70,7 @@ where
I::Error: ParseError<I::Item, I::Range, I::Position>,
{
digits().then(move |v| {
if contains(&range, &v) {
if range.contains(&v) {
value(v).left()
} else {
unexpected_any("digits out of range").right()