compiling with no errors whoop whoop!

This commit is contained in:
ripytide
2023-04-20 18:17:55 +01:00
parent 288d451d21
commit 2efd51d832
8 changed files with 67 additions and 84 deletions
+1 -1
View File
@@ -137,7 +137,7 @@ See Wikipedia's article on mathematical Intervals:
# Improvements/Caveats
- I had to create a new trait: [`TryFromBounds`] rather than using
- I had to create a new trait: [`TryFromDiscreteBounds`] rather than using
`TryFrom<(Bound, Bound)>` (relys on upstream to impl, see [this
thread](https://internals.rust-lang.org/t/range-should-impl-tryfrom-bound-bound))
@@ -29,7 +29,7 @@ use crate::stepable::Stepable;
///
/// [`Step`]: std::iter::Step
#[derive(Debug, Copy, Clone, Serialize, Deserialize)]
pub(crate) enum DiscreteBoundOrd<T> {
pub enum DiscreteBoundOrd<T> {
Included(T),
StartUnbounded,
EndUnbounded,
@@ -51,7 +51,7 @@ impl<I> DiscreteBoundOrd<I> {
pub fn up_if_finite(&self) -> DiscreteBoundOrd<I>
where
I: Stepable,
I: Stepable + Copy,
{
match self {
DiscreteBoundOrd::Included(x) => DiscreteBoundOrd::Included(x.up().unwrap()),
@@ -60,7 +60,7 @@ impl<I> DiscreteBoundOrd<I> {
}
pub fn down_if_finite(&self) -> DiscreteBoundOrd<I>
where
I: Stepable,
I: Stepable + Copy,
{
match self {
DiscreteBoundOrd::Included(x) => DiscreteBoundOrd::Included(x.down().unwrap()),
+2 -2
View File
@@ -19,7 +19,7 @@ along with range_bounds_map. If not, see <https://www.gnu.org/licenses/>.
use std::ops::{Bound, RangeBounds};
use crate::bound_ord::DiscreteBoundOrd;
use crate::discrete_bound_ord::DiscreteBoundOrd;
use crate::stepable::Stepable;
use crate::try_from_discrete_bounds::TryFromDiscreteBounds;
@@ -37,7 +37,7 @@ pub enum DiscreteBound<I> {
impl<I> DiscreteBound<I>
where
I: Stepable,
I: Stepable + Copy,
{
pub fn start(bound: Bound<I>) -> Self {
match bound {
+4 -4
View File
@@ -147,7 +147,7 @@ along with range_bounds_map. If not, see <https://www.gnu.org/licenses/>.
//!
//! # Improvements/Caveats
//!
//! - I had to create a new trait: [`TryFromBounds`] rather than using
//! - I had to create a new trait: [`TryFromDiscreteBounds`] rather than using
//! `TryFrom<(Bound, Bound)>` (relys on upstream to impl, see [this
//! thread](https://internals.rust-lang.org/t/range-should-impl-tryfrom-bound-bound))
//!
@@ -223,13 +223,13 @@ along with range_bounds_map. If not, see <https://www.gnu.org/licenses/>.
#![allow(clippy::tabs_in_doc_comments)]
#![allow(clippy::needless_return)]
//todo rename me
pub(crate) mod bound_ord;
pub mod test_ranges;
pub(crate) mod utils;
pub mod stepable;
pub mod discrete_bounds;
pub(crate) mod discrete_bound_ord;
pub mod stepable;
pub mod try_from_discrete_bounds;
pub mod range_bounds_map;
+18 -18
View File
@@ -30,7 +30,7 @@ use serde::de::{MapAccess, Visitor};
use serde::ser::SerializeMap;
use serde::{Deserialize, Deserializer, Serialize, Serializer};
use crate::bound_ord::DiscreteBoundOrd;
use crate::discrete_bound_ord::DiscreteBoundOrd;
use crate::discrete_bounds::{DiscreteBound, DiscreteBounds};
use crate::stepable::Stepable;
use crate::try_from_discrete_bounds::TryFromDiscreteBounds;
@@ -143,7 +143,7 @@ pub struct RangeBoundsMap<I, K, V> {
#[derive(PartialEq, Debug)]
pub struct OverlapError;
/// An error type to represent a failed [`TryFromBounds`] within a
/// An error type to represent a failed [`TryFromDiscreteBounds`] within a
/// method.
///
/// There are several methods that return this error, and some of the
@@ -161,7 +161,7 @@ pub struct OverlapError;
/// Bound::Exclusive(8))`. However, since the `RangeBounds` type of
/// 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
/// created via [`TryFromDiscreteBounds`] and [`RangeBoundsMap::cut()`] will
/// return Err(TryFromDiscreteBoundsError).
///
/// ```
@@ -201,7 +201,7 @@ pub struct OverlapError;
/// use std::ops::{Bound, RangeBounds};
///
/// use range_bounds_map::{
/// OverlapOrTryFromDiscreteBoundsError, RangeBoundsMap, TryFromBounds,
/// OverlapOrTryFromDiscreteBoundsError, RangeBoundsMap, TryFromDiscreteBounds,
/// TryFromDiscreteBoundsError,
/// };
///
@@ -234,7 +234,7 @@ pub struct OverlapError;
/// }
/// }
///
/// impl TryFromBounds<i8> for MultiBounds {
/// impl TryFromDiscreteBounds<i8> for MultiBounds {
/// fn try_from_bounds(
/// start_bound: Bound<i8>,
/// end_bound: Bound<i8>,
@@ -262,7 +262,7 @@ pub struct OverlapError;
/// MultiBounds::Exclusive(4, 6),
/// false
/// ),
/// Err(OverlapOrTryFromDiscreteBoundsError::TryFromBounds(
/// Err(OverlapOrTryFromDiscreteBoundsError::TryFromDiscreteBounds(
/// TryFromDiscreteBoundsError
/// ))
/// );
@@ -275,7 +275,7 @@ pub struct TryFromDiscreteBoundsError;
#[derive(PartialEq, Debug)]
pub enum OverlapOrTryFromDiscreteBoundsError {
Overlap(OverlapError),
TryFromBounds(TryFromDiscreteBoundsError),
TryFromDiscreteBounds(TryFromDiscreteBoundsError),
}
impl<I, K, V> RangeBoundsMap<I, K, V>
@@ -685,7 +685,7 @@ where
/// the full or partial ranges that were cut.
///
/// If the remaining ranges left in the map after the cut would
/// not be able be created with the [`TryFromBounds`] trait then a
/// not be able be created with the [`TryFromDiscreteBounds`] trait then a
/// [`TryFromDiscreteBoundsError`] will be returned and the map will not
/// be cut at all.
///
@@ -1097,7 +1097,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 [`TryFromDiscreteBoundsError`] will be
/// [`TryFromDiscreteBounds`] trait then a [`TryFromDiscreteBoundsError`] will be
/// returned.
///
/// # Panics
@@ -1180,7 +1180,7 @@ where
selfy.inner.remove(touching_end_comp(range.end()));
},
)
.map_err(OverlapOrTryFromDiscreteBoundsError::TryFromBounds)
.map_err(OverlapOrTryFromDiscreteBoundsError::TryFromDiscreteBounds)
}
/// Adds a new entry to the map and merges into other ranges in
@@ -1196,7 +1196,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 [`TryFromDiscreteBoundsError`] will be
/// [`TryFromDiscreteBounds`] trait then a [`TryFromDiscreteBoundsError`] will be
/// returned.
///
/// # Panics
@@ -1289,7 +1289,7 @@ where
}
},
)
.map_err(OverlapOrTryFromDiscreteBoundsError::TryFromBounds)
.map_err(OverlapOrTryFromDiscreteBoundsError::TryFromDiscreteBounds)
}
/// Adds a new entry to the map and merges into other ranges in
@@ -1302,7 +1302,7 @@ where
/// returned.
///
/// If the range merges other ranges and the merged-together range
/// cannot be created with the [`TryFromBounds`] trait then a
/// cannot be created with the [`TryFromDiscreteBounds`] trait then a
/// [`TryFromDiscreteBoundsError`] will be returned.
///
/// # Panics
@@ -1389,7 +1389,7 @@ where
/// returned.
///
/// If the range merges other ranges and the merged-together range
/// cannot be created with the [`TryFromBounds`] trait then a
/// cannot be created with the [`TryFromDiscreteBounds`] trait then a
/// [`TryFromDiscreteBoundsError`] will be returned.
///
/// # Panics
@@ -1486,7 +1486,7 @@ where
/// same `V: Clone` trait bound applies.
///
/// If the remaining ranges left after the cut are not able to be
/// created with the [`TryFromBounds`] trait then a
/// created with the [`TryFromDiscreteBounds`] trait then a
/// [`TryFromDiscreteBoundsError`] will be returned.
///
/// # Panics
@@ -2247,7 +2247,7 @@ mod tests {
assert_insert_merge_touching(
special(),
(mee(6, 7), true),
Err(OverlapOrTryFromDiscreteBoundsError::TryFromBounds(
Err(OverlapOrTryFromDiscreteBoundsError::TryFromDiscreteBounds(
TryFromDiscreteBoundsError,
)),
None::<[_; 0]>,
@@ -2261,7 +2261,7 @@ mod tests {
assert_insert_merge_touching(
special(),
(mee(12, 15), true),
Err(OverlapOrTryFromDiscreteBoundsError::TryFromBounds(
Err(OverlapOrTryFromDiscreteBoundsError::TryFromDiscreteBounds(
TryFromDiscreteBoundsError,
)),
None::<[_; 0]>,
@@ -2381,7 +2381,7 @@ mod tests {
assert_insert_merge_touching_if_values_equal(
special(),
(mee(12, 15), false),
Err(OverlapOrTryFromDiscreteBoundsError::TryFromBounds(
Err(OverlapOrTryFromDiscreteBoundsError::TryFromDiscreteBounds(
TryFromDiscreteBoundsError,
)),
None::<[_; 0]>,
+30 -45
View File
@@ -1,16 +1,16 @@
use std::fmt;
use std::marker::PhantomData;
use std::ops::Bound;
use serde::de::{SeqAccess, Visitor};
use serde::ser::SerializeSeq;
use serde::{Deserialize, Deserializer, Serialize, Serializer};
use crate::discrete_bounds::DiscreteBounds;
use crate::range_bounds_map::{IntoIter as RangeBoundsMapIntoIter, DiscreteRange};
use crate::range_bounds_map::{DiscreteRange, IntoIter as RangeBoundsMapIntoIter};
use crate::stepable::Stepable;
use crate::try_from_discrete_bounds::TryFromDiscreteBounds;
use crate::{
OverlapError, OverlapOrTryFromDiscreteBoundsError, RangeBoundsMap,
TryFromDiscreteBoundsError,
OverlapError, OverlapOrTryFromDiscreteBoundsError, RangeBoundsMap, TryFromDiscreteBoundsError,
};
/// An ordered set of non-overlapping ranges based on [`RangeBoundsMap`].
@@ -33,8 +33,8 @@ pub struct RangeBoundsSet<I, K> {
impl<I, K> RangeBoundsSet<I, K>
where
I: Ord + Copy,
K: DiscreteRange<I>,
I: Ord + Copy + Stepable,
K: DiscreteRange<I> + Copy,
{
/// See [`RangeBoundsMap::new()`] for more details.
pub fn new() -> Self {
@@ -53,22 +53,19 @@ where
/// See [`RangeBoundsMap::overlaps()`] for more details.
pub fn overlaps<Q>(&self, range: Q) -> bool
where
Q: DiscreteRange<I>,
Q: DiscreteRange<I> + Copy,
{
self.inner.overlaps(range)
}
/// See [`RangeBoundsMap::overlapping()`] for more details.
pub fn overlapping<Q>(
&self,
range: Q,
) -> impl DoubleEndedIterator<Item = &K>
pub fn overlapping<Q>(&self, range: Q) -> impl DoubleEndedIterator<Item = &K>
where
Q: DiscreteRange<I>,
Q: DiscreteRange<I> + Copy,
{
self.inner.overlapping(range).map(first)
}
/// See [`RangeBoundsMap::get_entry_at_point()`] for more details.
pub fn get_at_point(&self, point: I) -> Result<K, (Bound<I>, Bound<I>)> {
pub fn get_at_point(&self, point: I) -> Result<K, DiscreteBounds<I>> {
self.inner.get_entry_at_point(point).map(first).copied()
}
/// See [`RangeBoundsMap::contains_point()`] for more details.
@@ -80,12 +77,9 @@ where
self.inner.iter().map(first)
}
/// See [`RangeBoundsMap::remove_overlapping()`] for more details.
pub fn remove_overlapping<'a, Q>(
&'a mut self,
range: Q,
) -> impl Iterator<Item = K> + '_
pub fn remove_overlapping<'a, Q>(&'a mut self, range: Q) -> impl Iterator<Item = K> + '_
where
Q: DiscreteRange<I> + 'a,
Q: DiscreteRange<I> + Copy + 'a,
{
self.inner.remove_overlapping(range).map(first)
}
@@ -93,13 +87,10 @@ where
pub fn cut<'a, Q>(
&'a mut self,
range: Q,
) -> Result<
impl Iterator<Item = (Bound<I>, Bound<I>)> + '_,
TryFromDiscreteBoundsError,
>
) -> Result<impl Iterator<Item = DiscreteBounds<I>> + '_, TryFromDiscreteBoundsError>
where
Q: DiscreteRange<I> + 'a,
K: TryFrom<DiscreteBounds<I>>,
Q: DiscreteRange<I> + Copy + 'a,
K: TryFromDiscreteBounds<I>,
{
self.inner.cut(range).map(|x| x.map(first))
}
@@ -107,16 +98,16 @@ where
pub fn gaps<'a, Q>(
&'a self,
range: Q,
) -> impl DoubleEndedIterator<Item = (Bound<I>, Bound<I>)> + '_
) -> impl DoubleEndedIterator<Item = DiscreteBounds<I>> + '_
where
Q: DiscreteRange<I> + 'a,
Q: DiscreteRange<I> + Copy + 'a,
{
self.inner.gaps(range)
}
/// See [`RangeBoundsMap::contains_range()`] for more details.
pub fn contains_range<Q>(&self, range: Q) -> bool
where
Q: DiscreteRange<I>,
Q: DiscreteRange<I> + Copy,
{
self.inner.contains_range(range)
}
@@ -130,17 +121,14 @@ where
range: K,
) -> Result<K, OverlapOrTryFromDiscreteBoundsError>
where
K: TryFrom<DiscreteBounds<I>>,
K: TryFromDiscreteBounds<I>,
{
self.inner.insert_merge_touching(range, ())
}
/// See [`RangeBoundsMap::insert_merge_overlapping()`] for more details.
pub fn insert_merge_overlapping(
&mut self,
range: K,
) -> Result<K, TryFromDiscreteBoundsError>
pub fn insert_merge_overlapping(&mut self, range: K) -> Result<K, TryFromDiscreteBoundsError>
where
K: TryFrom<DiscreteBounds<I>>,
K: TryFromDiscreteBounds<I>,
{
self.inner.insert_merge_overlapping(range, ())
}
@@ -150,17 +138,14 @@ where
range: K,
) -> Result<K, TryFromDiscreteBoundsError>
where
K: TryFrom<DiscreteBounds<I>>,
K: TryFromDiscreteBounds<I>,
{
self.inner.insert_merge_touching_or_overlapping(range, ())
}
/// See [`RangeBoundsMap::insert_overwrite()`] for more details.
pub fn insert_overwrite(
&mut self,
range: K,
) -> Result<(), TryFromDiscreteBoundsError>
pub fn insert_overwrite(&mut self, range: K) -> Result<(), TryFromDiscreteBoundsError>
where
K: TryFrom<DiscreteBounds<I>>,
K: TryFromDiscreteBounds<I>,
{
self.inner.insert_overwrite(range, ())
}
@@ -232,8 +217,8 @@ where
impl<I, K> Serialize for RangeBoundsSet<I, K>
where
I: Ord + Copy,
K: DiscreteRange<I> + Serialize,
I: Ord + Copy + Stepable,
K: DiscreteRange<I> + Copy + Serialize,
{
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
where
@@ -249,8 +234,8 @@ where
impl<'de, I, K> Deserialize<'de> for RangeBoundsSet<I, K>
where
I: Ord + Copy,
K: DiscreteRange<I> + Deserialize<'de>,
I: Ord + Copy + Stepable,
K: DiscreteRange<I> + Copy + Deserialize<'de>,
{
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
where
@@ -270,8 +255,8 @@ struct RangeBoundsSetVisitor<I, K> {
impl<'de, I, K> Visitor<'de> for RangeBoundsSetVisitor<I, K>
where
I: Ord + Copy,
K: DiscreteRange<I> + Deserialize<'de>,
I: Ord + Copy + Stepable,
K: DiscreteRange<I> + Copy + Deserialize<'de>,
{
type Value = RangeBoundsSet<I, K>;
-2
View File
@@ -1,5 +1,3 @@
use std::ops::Bound;
use crate::discrete_bounds::{DiscreteBound, DiscreteBounds};
use crate::stepable::Stepable;
+9 -9
View File
@@ -19,7 +19,7 @@ along with range_bounds_map. If not, see <https://www.gnu.org/licenses/>.
use std::cmp::Ordering;
use crate::bound_ord::DiscreteBoundOrd;
use crate::discrete_bound_ord::DiscreteBoundOrd;
use crate::discrete_bounds::DiscreteBounds;
use crate::range_bounds_map::DiscreteRange;
use crate::stepable::Stepable;
@@ -53,8 +53,8 @@ pub(crate) enum Config {
}
pub(crate) fn config<I, A, B>(a: A, b: B) -> Config
where
A: DiscreteRange<I>,
B: DiscreteRange<I>,
A: DiscreteRange<I> + Copy,
B: DiscreteRange<I> + Copy,
I: Ord,
{
match a.start() < b.start() {
@@ -99,8 +99,8 @@ enum SortedConfig<I> {
}
fn sorted_config<I, A, B>(a: A, b: B) -> SortedConfig<I>
where
A: DiscreteRange<I>,
B: DiscreteRange<I>,
A: DiscreteRange<I> + Copy,
B: DiscreteRange<I> + Copy,
I: Ord,
{
let ae = (a.start(), a.end());
@@ -132,8 +132,8 @@ pub(crate) struct CutResult<I> {
}
pub(crate) fn cut_range<I, B, C>(base: B, cut: C) -> CutResult<I>
where
B: DiscreteRange<I>,
C: DiscreteRange<I>,
B: DiscreteRange<I> + Copy,
C: DiscreteRange<I> + Copy,
I: Ord + Copy + Stepable,
{
let mut result = CutResult {
@@ -222,8 +222,8 @@ where
pub(crate) fn overlaps<I, A, B>(a: A, b: B) -> bool
where
A: DiscreteRange<I>,
B: DiscreteRange<I>,
A: DiscreteRange<I> + Copy,
B: DiscreteRange<I> + Copy,
I: Ord,
{
!matches!(sorted_config(a, b), SortedConfig::NonOverlapping(_, _))