diff --git a/src/lib.rs b/src/lib.rs index f64a048..acd1f92 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -236,7 +236,7 @@ pub mod range_bounds_map; pub mod range_bounds_set; pub use crate::range_bounds_map::{ - OverlapError, OverlapOrTryFromBoundsError, RangeBoundsMap, - TryFromBoundsError, + OverlapError, OverlapOrTryFromDiscreteBoundsError, RangeBoundsMap, + TryFromDiscreteBoundsError, }; pub use crate::range_bounds_set::RangeBoundsSet; diff --git a/src/range_bounds_map.rs b/src/range_bounds_map.rs index a0f4ef4..0cfd6c5 100644 --- a/src/range_bounds_map.rs +++ b/src/range_bounds_map.rs @@ -151,7 +151,7 @@ pub struct OverlapError; /// /// # Example with [`RangeBoundsMap::cut()`] /// -/// The first way you may recieve [`TryFromBoundsError`] is from +/// The first way you may recieve [`TryFromDiscreteBoundsError`] is from /// [`RangeBoundsMap::cut()`]. /// /// In this example we try to cut `ii(4, 6)` out of a `RangeBoundsMap` @@ -161,11 +161,11 @@ pub struct OverlapError; /// this `RangeBoundsMap` is `Range<{integer}>` the latter of the two /// new `RangeBounds` is "unrepresentable", and hence will fail to be /// created via [`TryFromBounds`] and [`RangeBoundsMap::cut()`] will -/// return Err(TryFromBoundsError). +/// return Err(TryFromDiscreteBoundsError). /// /// ``` /// use range_bounds_map::test_ranges::{ie_strict, ii}; -/// use range_bounds_map::{RangeBoundsMap, TryFromBoundsError}; +/// use range_bounds_map::{RangeBoundsMap, TryFromDiscreteBoundsError}; /// /// let mut map = /// RangeBoundsMap::from_slice_strict([(ie_strict(2, 8), true)]) @@ -176,7 +176,7 @@ pub struct OverlapError; /// /// # Example with `insert_merge_*` functions. /// -/// The second and final way you may recieve a [`TryFromBoundsError`] +/// The second and final way you may recieve a [`TryFromDiscreteBoundsError`] /// is via merging methods such as /// [`RangeBoundsMap::insert_merge_touching`]. /// @@ -200,8 +200,8 @@ pub struct OverlapError; /// use std::ops::{Bound, RangeBounds}; /// /// use range_bounds_map::{ -/// OverlapOrTryFromBoundsError, RangeBoundsMap, TryFromBounds, -/// TryFromBoundsError, +/// OverlapOrTryFromDiscreteBoundsError, RangeBoundsMap, TryFromBounds, +/// TryFromDiscreteBoundsError, /// }; /// /// #[derive(Debug, Copy, Clone, PartialEq)] @@ -237,7 +237,7 @@ pub struct OverlapError; /// fn try_from_bounds( /// start_bound: Bound, /// end_bound: Bound, -/// ) -> Result { +/// ) -> Result { /// match (start_bound, end_bound) { /// (Bound::Included(start), Bound::Included(end)) => { /// Ok(MultiBounds::Inclusive(start, end)) @@ -245,7 +245,7 @@ pub struct OverlapError; /// (Bound::Excluded(start), Bound::Excluded(end)) => { /// Ok(MultiBounds::Exclusive(start, end)) /// } -/// _ => Err(TryFromBoundsError), +/// _ => Err(TryFromDiscreteBoundsError), /// } /// } /// } @@ -261,20 +261,20 @@ pub struct OverlapError; /// MultiBounds::Exclusive(4, 6), /// false /// ), -/// Err(OverlapOrTryFromBoundsError::TryFromBounds( -/// TryFromBoundsError +/// Err(OverlapOrTryFromDiscreteBoundsError::TryFromBounds( +/// TryFromDiscreteBoundsError /// )) /// ); /// ``` #[derive(PartialEq, Debug)] -pub struct TryFromBoundsError; +pub struct TryFromDiscreteBoundsError; /// An error type to represent either an [`OverlapError`] or a -/// [`TryFromBoundsError`]. +/// [`TryFromDiscreteBoundsError`]. #[derive(PartialEq, Debug)] -pub enum OverlapOrTryFromBoundsError { +pub enum OverlapOrTryFromDiscreteBoundsError { Overlap(OverlapError), - TryFromBounds(TryFromBoundsError), + TryFromBounds(TryFromDiscreteBoundsError), } impl RangeBoundsMap @@ -685,7 +685,7 @@ where /// /// If the remaining ranges left in the map after the cut would /// not be able be created with the [`TryFromBounds`] trait then a - /// [`TryFromBoundsError`] will be returned and the map will not + /// [`TryFromDiscreteBoundsError`] will be returned and the map will not /// be cut at all. /// /// `V` must implement `Clone` as if you try to cut out the center @@ -704,7 +704,7 @@ where /// use std::ops::Bound; /// /// use range_bounds_map::test_ranges::{ie, ie_strict, ii}; - /// use range_bounds_map::{RangeBoundsMap, TryFromBoundsError}; + /// use range_bounds_map::{RangeBoundsMap, TryFromDiscreteBoundsError}; /// /// let mut base = RangeBoundsMap::from_slice_strict([ /// (ie_strict(1, 4), false), @@ -733,11 +733,11 @@ where pub fn cut<'a, Q>( &'a mut self, range: Q, - ) -> Result, V)> + '_, TryFromBoundsError> + ) -> Result, V)> + '_, TryFromDiscreteBoundsError> where Q: DiscreteRange + Copy + 'a, K: TryFrom>, - TryFromBoundsError: From, + TryFromDiscreteBoundsError: From, V: Clone, { invalid_range_panic(range); @@ -766,11 +766,11 @@ where &mut self, range: Q, single_overlapping_range: K, - ) -> Result, V)>, TryFromBoundsError> + ) -> Result, V)>, TryFromDiscreteBoundsError> where Q: DiscreteRange + Copy, K: TryFrom>, - TryFromBoundsError: From, + TryFromDiscreteBoundsError: From, V: Clone, { invalid_range_panic(range); @@ -801,11 +801,11 @@ where range: Q, left_overlapping: Option, right_overlapping: Option, - ) -> Result, V)> + '_, TryFromBoundsError> + ) -> Result, V)> + '_, TryFromDiscreteBoundsError> where Q: DiscreteRange + Copy + 'a, K: TryFrom>, - TryFromBoundsError: From, + TryFromDiscreteBoundsError: From, V: Clone, { invalid_range_panic(range); @@ -1043,10 +1043,10 @@ where get_end: G2, remove_start: R1, remove_end: R2, - ) -> Result + ) -> Result where K: TryFrom>, - TryFromBoundsError: From, + TryFromDiscreteBoundsError: From, G1: FnOnce(&Self, &V) -> Option, G2: FnOnce(&Self, &V) -> Option, R1: FnOnce(&mut Self, &V), @@ -1098,7 +1098,7 @@ where /// /// If the range merges with one or two touching ranges and the /// merged-together range cannot be created with the - /// [`TryFromBounds`] trait then a [`TryFromBoundsError`] will be + /// [`TryFromBounds`] trait then a [`TryFromDiscreteBoundsError`] will be /// returned. /// /// # Panics @@ -1111,7 +1111,7 @@ where /// ``` /// use range_bounds_map::test_ranges::ie; /// use range_bounds_map::{ - /// OverlapError, OverlapOrTryFromBoundsError, RangeBoundsMap, + /// OverlapError, OverlapOrTryFromDiscreteBoundsError, RangeBoundsMap, /// }; /// /// let mut map = RangeBoundsMap::from_slice_strict([ @@ -1129,7 +1129,7 @@ where /// // Overlapping /// assert_eq!( /// map.insert_merge_touching(ie(4, 8), false), - /// Err(OverlapOrTryFromBoundsError::Overlap(OverlapError)), + /// Err(OverlapOrTryFromDiscreteBoundsError::Overlap(OverlapError)), /// ); /// /// // Neither Touching or Overlapping @@ -1147,15 +1147,15 @@ where &mut self, range: K, value: V, - ) -> Result + ) -> Result where K: TryFrom>, - TryFromBoundsError: From, + TryFromDiscreteBoundsError: From, { invalid_range_panic(range); if self.overlaps(range) { - return Err(OverlapOrTryFromBoundsError::Overlap(OverlapError)); + return Err(OverlapOrTryFromDiscreteBoundsError::Overlap(OverlapError)); } self.insert_merge_with_comps( @@ -1182,7 +1182,7 @@ where selfy.inner.remove(touching_end_comp(range.end())); }, ) - .map_err(OverlapOrTryFromBoundsError::TryFromBounds) + .map_err(OverlapOrTryFromDiscreteBoundsError::TryFromBounds) } /// Adds a new entry to the map and merges into other ranges in @@ -1198,7 +1198,7 @@ where /// /// If the range merges with one or two touching ranges and the /// merged-together range cannot be created with the - /// [`TryFromBounds`] trait then a [`TryFromBoundsError`] will be + /// [`TryFromBounds`] trait then a [`TryFromDiscreteBoundsError`] will be /// returned. /// /// # Panics @@ -1211,7 +1211,7 @@ where /// ``` /// use range_bounds_map::test_ranges::ie; /// use range_bounds_map::{ - /// OverlapError, OverlapOrTryFromBoundsError, RangeBoundsMap, + /// OverlapError, OverlapOrTryFromDiscreteBoundsError, RangeBoundsMap, /// }; /// /// let mut map = RangeBoundsMap::from_slice_strict([ @@ -1229,7 +1229,7 @@ where /// // Overlapping /// assert_eq!( /// map.insert_merge_touching_if_values_equal(ie(4, 8), false), - /// Err(OverlapOrTryFromBoundsError::Overlap(OverlapError)), + /// Err(OverlapOrTryFromDiscreteBoundsError::Overlap(OverlapError)), /// ); /// /// // Neither Touching or Overlapping @@ -1247,16 +1247,16 @@ where &mut self, range: K, value: V, - ) -> Result + ) -> Result where K: TryFrom>, - TryFromBoundsError: From, + TryFromDiscreteBoundsError: From, V: Eq, { invalid_range_panic(range); if self.overlaps(range) { - return Err(OverlapOrTryFromBoundsError::Overlap(OverlapError)); + return Err(OverlapOrTryFromDiscreteBoundsError::Overlap(OverlapError)); } let get_start = |selfy: &Self, value: &V| { @@ -1292,7 +1292,7 @@ where } }, ) - .map_err(OverlapOrTryFromBoundsError::TryFromBounds) + .map_err(OverlapOrTryFromDiscreteBoundsError::TryFromBounds) } /// Adds a new entry to the map and merges into other ranges in @@ -1306,7 +1306,7 @@ where /// /// If the range merges other ranges and the merged-together range /// cannot be created with the [`TryFromBounds`] trait then a - /// [`TryFromBoundsError`] will be returned. + /// [`TryFromDiscreteBoundsError`] will be returned. /// /// # Panics /// @@ -1318,7 +1318,7 @@ where /// ``` /// use range_bounds_map::test_ranges::ie; /// use range_bounds_map::{ - /// OverlapError, OverlapOrTryFromBoundsError, RangeBoundsMap, + /// OverlapError, OverlapOrTryFromDiscreteBoundsError, RangeBoundsMap, /// }; /// /// let mut map = RangeBoundsMap::from_slice_strict([ @@ -1350,10 +1350,10 @@ where /// [(ie(1, 4), false), (ie(4, 8), false), (ie(10, 16), false)] /// ); /// ``` - pub fn insert_merge_overlapping(&mut self, range: K, value: V) -> Result + pub fn insert_merge_overlapping(&mut self, range: K, value: V) -> Result where K: TryFrom>, - TryFromBoundsError: From, + TryFromDiscreteBoundsError: From, { invalid_range_panic(range); @@ -1390,7 +1390,7 @@ where /// /// If the range merges other ranges and the merged-together range /// cannot be created with the [`TryFromBounds`] trait then a - /// [`TryFromBoundsError`] will be returned. + /// [`TryFromDiscreteBoundsError`] will be returned. /// /// # Panics /// @@ -1402,7 +1402,7 @@ where /// ``` /// use range_bounds_map::test_ranges::ie; /// use range_bounds_map::{ - /// OverlapError, OverlapOrTryFromBoundsError, RangeBoundsMap, + /// OverlapError, OverlapOrTryFromDiscreteBoundsError, RangeBoundsMap, /// }; /// /// let mut map = RangeBoundsMap::from_slice_strict([ @@ -1438,10 +1438,10 @@ where &mut self, range: K, value: V, - ) -> Result + ) -> Result where K: TryFrom>, - TryFromBoundsError: From, + TryFromDiscreteBoundsError: From, { invalid_range_panic(range); @@ -1488,7 +1488,7 @@ where /// /// If the remaining ranges left after the cut are not able to be /// created with the [`TryFromBounds`] trait then a - /// [`TryFromBoundsError`] will be returned. + /// [`TryFromDiscreteBoundsError`] will be returned. /// /// # Panics /// @@ -1512,10 +1512,10 @@ where /// [(ie(2, 4), false), (ie(4, 6), true), (ie(6, 8), false)] /// ); /// ``` - pub fn insert_overwrite(&mut self, range: K, value: V) -> Result<(), TryFromBoundsError> + pub fn insert_overwrite(&mut self, range: K, value: V) -> Result<(), TryFromDiscreteBoundsError> where K: TryFrom>, - TryFromBoundsError: From, + TryFromDiscreteBoundsError: From, V: Clone, { invalid_range_panic(range); @@ -1584,7 +1584,7 @@ where /// # Examples /// ``` /// use range_bounds_map::test_ranges::ie; - /// use range_bounds_map::{RangeBoundsMap, TryFromBoundsError}; + /// use range_bounds_map::{RangeBoundsMap, TryFromDiscreteBoundsError}; /// /// let map = RangeBoundsMap::from_slice_strict([ /// (ie(1, 4), false), @@ -2086,13 +2086,13 @@ mod tests { assert_cut( special(), mii(5, 6), - Err::<[_; 0], _>(TryFromBoundsError), + Err::<[_; 0], _>(TryFromDiscreteBoundsError), None::<[_; 0]>, ); assert_cut( special(), mii(6, 7), - Err::<[_; 0], _>(TryFromBoundsError), + Err::<[_; 0], _>(TryFromDiscreteBoundsError), None::<[_; 0]>, ); assert_cut( @@ -2104,7 +2104,7 @@ mod tests { assert_cut( special(), mii(7, 10), - Err::<[_; 0], _>(TryFromBoundsError), + Err::<[_; 0], _>(TryFromDiscreteBoundsError), None::<[_; 0]>, ); assert_cut( @@ -2123,12 +2123,12 @@ mod tests { fn assert_cut( mut before: RangeBoundsMap, to_cut: Q, - result: Result<[(DiscreteBounds, V); Y], TryFromBoundsError>, + result: Result<[(DiscreteBounds, V); Y], TryFromDiscreteBoundsError>, after: Option<[(K, V); N]>, ) where I: Ord + Debug + Copy + Stepable, K: DiscreteRange + TryFrom> + PartialEq + Debug + Copy, - TryFromBoundsError: From, + TryFromDiscreteBoundsError: From, Q: DiscreteRange + Copy, V: PartialEq + Debug + Clone, { @@ -2180,7 +2180,7 @@ mod tests { assert_insert_merge_touching( basic(), (ii(0, 4), false), - Err(OverlapOrTryFromBoundsError::Overlap(OverlapError)), + Err(OverlapOrTryFromDiscreteBoundsError::Overlap(OverlapError)), None::<[_; 0]>, ); assert_insert_merge_touching( @@ -2238,41 +2238,41 @@ mod tests { assert_insert_merge_touching( special(), (mee(6, 7), true), - Err(OverlapOrTryFromBoundsError::TryFromBounds( - TryFromBoundsError, + Err(OverlapOrTryFromDiscreteBoundsError::TryFromBounds( + TryFromDiscreteBoundsError, )), None::<[_; 0]>, ); assert_insert_merge_touching( special(), (mii(6, 7), true), - Err(OverlapOrTryFromBoundsError::Overlap(OverlapError)), + Err(OverlapOrTryFromDiscreteBoundsError::Overlap(OverlapError)), None::<[_; 0]>, ); assert_insert_merge_touching( special(), (mee(12, 15), true), - Err(OverlapOrTryFromBoundsError::TryFromBounds( - TryFromBoundsError, + Err(OverlapOrTryFromDiscreteBoundsError::TryFromBounds( + TryFromDiscreteBoundsError, )), None::<[_; 0]>, ); assert_insert_merge_touching( special(), (mii(12, 15), true), - Err(OverlapOrTryFromBoundsError::Overlap(OverlapError)), + Err(OverlapOrTryFromDiscreteBoundsError::Overlap(OverlapError)), None::<[_; 0]>, ); } fn assert_insert_merge_touching( mut before: RangeBoundsMap, to_insert: (K, V), - result: Result, + result: Result, after: Option<[(K, V); N]>, ) where I: Ord + Debug + Copy + Stepable, K: DiscreteRange + TryFrom> + PartialEq + Debug + Copy, - TryFromBoundsError: From, + TryFromDiscreteBoundsError: From, V: PartialEq + Debug + Clone, { let clone = before.clone(); @@ -2292,7 +2292,7 @@ mod tests { assert_insert_merge_touching_if_values_equal( basic(), (ii(0, 4), false), - Err(OverlapOrTryFromBoundsError::Overlap(OverlapError)), + Err(OverlapOrTryFromDiscreteBoundsError::Overlap(OverlapError)), None::<[_; 0]>, ); assert_insert_merge_touching_if_values_equal( @@ -2367,33 +2367,33 @@ mod tests { assert_insert_merge_touching_if_values_equal( special(), (mii(6, 7), true), - Err(OverlapOrTryFromBoundsError::Overlap(OverlapError)), + Err(OverlapOrTryFromDiscreteBoundsError::Overlap(OverlapError)), None::<[_; 0]>, ); assert_insert_merge_touching_if_values_equal( special(), (mee(12, 15), false), - Err(OverlapOrTryFromBoundsError::TryFromBounds( - TryFromBoundsError, + Err(OverlapOrTryFromDiscreteBoundsError::TryFromBounds( + TryFromDiscreteBoundsError, )), None::<[_; 0]>, ); assert_insert_merge_touching_if_values_equal( special(), (mii(12, 15), true), - Err(OverlapOrTryFromBoundsError::Overlap(OverlapError)), + Err(OverlapOrTryFromDiscreteBoundsError::Overlap(OverlapError)), None::<[_; 0]>, ); } fn assert_insert_merge_touching_if_values_equal( mut before: RangeBoundsMap, to_insert: (K, V), - result: Result, + result: Result, after: Option<[(K, V); N]>, ) where I: Ord + Debug + Copy + Stepable, K: DiscreteRange + TryFrom> + PartialEq + Debug + Copy, - TryFromBoundsError: From, + TryFromDiscreteBoundsError: From, V: Eq + Debug + Clone, { let clone = before.clone(); @@ -2461,7 +2461,7 @@ mod tests { assert_insert_merge_overlapping( special(), (mee(10, 18), true), - Err(TryFromBoundsError), + Err(TryFromDiscreteBoundsError), None::<[_; 0]>, ); assert_insert_merge_overlapping( @@ -2486,12 +2486,12 @@ mod tests { fn assert_insert_merge_overlapping( mut before: RangeBoundsMap, to_insert: (K, V), - result: Result, + result: Result, after: Option<[(K, V); N]>, ) where I: Ord + Debug + Copy + Stepable, K: DiscreteRange + TryFrom> + PartialEq + Debug + Copy, - TryFromBoundsError: From, + TryFromDiscreteBoundsError: From, V: PartialEq + Debug + Clone, { let clone = before.clone(); @@ -2580,7 +2580,7 @@ mod tests { assert_insert_merge_touching_or_overlapping( special(), (mee(10, 18), true), - Err(TryFromBoundsError), + Err(TryFromDiscreteBoundsError), None::<[_; 0]>, ); assert_insert_merge_touching_or_overlapping( @@ -2592,7 +2592,7 @@ mod tests { assert_insert_merge_touching_or_overlapping( special(), (mee(7, 8), false), - Err(TryFromBoundsError), + Err(TryFromDiscreteBoundsError), None::<[_; 0]>, ); assert_insert_merge_touching_or_overlapping( @@ -2605,25 +2605,25 @@ mod tests { assert_insert_merge_touching_or_overlapping( special(), (mee(6, 7), true), - Err(TryFromBoundsError), + Err(TryFromDiscreteBoundsError), None::<[_; 0]>, ); assert_insert_merge_touching_or_overlapping( special(), (mee(12, 15), true), - Err(TryFromBoundsError), + Err(TryFromDiscreteBoundsError), None::<[_; 0]>, ); } fn assert_insert_merge_touching_or_overlapping( mut before: RangeBoundsMap, to_insert: (K, V), - result: Result, + result: Result, after: Option<[(K, V); N]>, ) where I: Ord + Debug + Copy + Stepable, K: DiscreteRange + TryFrom> + PartialEq + Debug, - TryFromBoundsError: From, + TryFromDiscreteBoundsError: From, V: PartialEq + Debug + Clone, { let clone = before.clone(); diff --git a/src/range_bounds_set.rs b/src/range_bounds_set.rs index 3a26d10..461fe27 100644 --- a/src/range_bounds_set.rs +++ b/src/range_bounds_set.rs @@ -9,8 +9,8 @@ use serde::{Deserialize, Deserializer, Serialize, Serializer}; use crate::discrete_bounds::DiscreteBounds; use crate::range_bounds_map::{IntoIter as RangeBoundsMapIntoIter, DiscreteRange}; use crate::{ - OverlapError, OverlapOrTryFromBoundsError, RangeBoundsMap, - TryFromBoundsError, + OverlapError, OverlapOrTryFromDiscreteBoundsError, RangeBoundsMap, + TryFromDiscreteBoundsError, }; /// An ordered set of non-overlapping ranges based on [`RangeBoundsMap`]. @@ -95,7 +95,7 @@ where range: Q, ) -> Result< impl Iterator, Bound)> + '_, - TryFromBoundsError, + TryFromDiscreteBoundsError, > where Q: DiscreteRange + 'a, @@ -128,7 +128,7 @@ where pub fn insert_merge_touching( &mut self, range: K, - ) -> Result + ) -> Result where K: TryFrom>, { @@ -138,7 +138,7 @@ where pub fn insert_merge_overlapping( &mut self, range: K, - ) -> Result + ) -> Result where K: TryFrom>, { @@ -148,7 +148,7 @@ where pub fn insert_merge_touching_or_overlapping( &mut self, range: K, - ) -> Result + ) -> Result where K: TryFrom>, { @@ -158,7 +158,7 @@ where pub fn insert_overwrite( &mut self, range: K, - ) -> Result<(), TryFromBoundsError> + ) -> Result<(), TryFromDiscreteBoundsError> where K: TryFrom>, {