diff --git a/src/lib.rs b/src/lib.rs index 872a1b6..f8fc289 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -232,11 +232,9 @@ pub mod discrete_bounds; pub mod range_bounds_map; pub mod range_bounds_set; -pub mod try_from_bounds; pub use crate::range_bounds_map::{ OverlapError, OverlapOrTryFromBoundsError, RangeBoundsMap, TryFromBoundsError, }; pub use crate::range_bounds_set::RangeBoundsSet; -pub use crate::try_from_bounds::TryFromBounds; diff --git a/src/range_bounds_map.rs b/src/range_bounds_map.rs index 9cb5fb4..008a9e4 100644 --- a/src/range_bounds_map.rs +++ b/src/range_bounds_map.rs @@ -33,10 +33,10 @@ use serde::ser::SerializeMap; use serde::{Deserialize, Deserializer, Serialize, Serializer}; use crate::bound_ord::DiscreteBoundOrd; +use crate::discrete_bounds::DiscreteBounds; use crate::utils::{ - cmp_range_with_bound_ord, cut_range, flip_bound, is_valid_range, overlaps, + cmp_range_with_discrete_bound_ord, cut_range, flip_bound, is_valid_range, overlaps, }; -use crate::TryFromBounds; /// An ordered map of non-overlapping ranges based on [`BTreeMap`]. /// @@ -756,7 +756,7 @@ where > where Q: NiceRange + 'a, - K: TryFromBounds, + K: TryFrom>, V: Clone, { invalid_range_panic(range); @@ -1679,7 +1679,7 @@ where K: NiceRange, { move |inner_range: &K| { - cmp_range_with_bound_ord(*inner_range, DiscreteBoundOrd::start(start)) + cmp_range_with_discrete_bound_ord(*inner_range, DiscreteBoundOrd::start(start)) } } fn overlapping_end_comp(end: Bound) -> impl FnMut(&K) -> Ordering @@ -1688,7 +1688,7 @@ where K: NiceRange, { move |inner_range: &K| { - cmp_range_with_bound_ord(*inner_range, DiscreteBoundOrd::end(end)) + cmp_range_with_discrete_bound_ord(*inner_range, DiscreteBoundOrd::end(end)) } } fn touching_start_comp(start: Bound) -> impl FnMut(&K) -> Ordering @@ -1751,8 +1751,8 @@ where /// already implement RangeBounds and Copy on your type then this will /// also be implemted. pub trait NiceRange: Copy { - fn start(&self) -> Bound; - fn end(&self) -> Bound; + fn start(&self) -> DiscreteBoundOrd; + fn end(&self) -> DiscreteBoundOrd; } impl NiceRange for K where diff --git a/src/range_bounds_set.rs b/src/range_bounds_set.rs index 350e147..e2be2ff 100644 --- a/src/range_bounds_set.rs +++ b/src/range_bounds_set.rs @@ -8,7 +8,7 @@ use serde::{Deserialize, Deserializer, Serialize, Serializer}; use crate::range_bounds_map::{IntoIter as RangeBoundsMapIntoIter, NiceRange}; use crate::{ - OverlapError, OverlapOrTryFromBoundsError, RangeBoundsMap, TryFromBounds, + OverlapError, OverlapOrTryFromBoundsError, RangeBoundsMap, TryFromBoundsError, }; diff --git a/src/test_ranges.rs b/src/test_ranges.rs index 8bca011..6867092 100644 --- a/src/test_ranges.rs +++ b/src/test_ranges.rs @@ -1,6 +1,6 @@ use std::ops::{Bound, RangeBounds}; -use crate::{TryFromBounds, TryFromBoundsError}; +use crate::{TryFromBoundsError}; pub type AnyRange = (Bound, Bound); @@ -57,20 +57,3 @@ impl RangeBounds for InExRange { Bound::Excluded(&self.end) } } - -impl TryFromBounds for InExRange { - fn try_from_bounds( - start_bound: Bound, - end_bound: Bound, - ) -> Result - where - Self: Sized, - { - match (start_bound, end_bound) { - (Bound::Included(start), Bound::Excluded(end)) => { - Ok(InExRange { start, end }) - } - _ => Err(TryFromBoundsError), - } - } -} diff --git a/src/utils.rs b/src/utils.rs index d3fc9ed..62c0ff7 100644 --- a/src/utils.rs +++ b/src/utils.rs @@ -23,17 +23,17 @@ use std::ops::Bound; use crate::bound_ord::DiscreteBoundOrd; use crate::range_bounds_map::NiceRange; -pub(crate) fn cmp_range_with_bound_ord( +pub(crate) fn cmp_range_with_discrete_bound_ord( range: A, - bound_ord: DiscreteBoundOrd, + discrete_bound_ord: DiscreteBoundOrd, ) -> Ordering where A: NiceRange, B: Ord, { - if bound_ord < DiscreteBoundOrd::start(range.start()) { + if discrete_bound_ord < range.start() { Ordering::Less - } else if bound_ord > DiscreteBoundOrd::end(range.end()) { + } else if discrete_bound_ord > range.end() { Ordering::Greater } else { Ordering::Equal @@ -56,7 +56,9 @@ where B: NiceRange, I: Ord, { - match DiscreteBoundOrd::start(a.start()) < DiscreteBoundOrd::start(b.start()) { + match DiscreteBoundOrd::start(a.start()) + < DiscreteBoundOrd::start(b.start()) + { true => { match ( contains_bound_ord(a, DiscreteBoundOrd::start(b.start())), @@ -110,7 +112,10 @@ where } } -pub(crate) fn contains_bound_ord(range: A, bound_ord: DiscreteBoundOrd) -> bool +pub(crate) fn contains_bound_ord( + range: A, + bound_ord: DiscreteBoundOrd, +) -> bool where A: NiceRange, I: Ord,