duplicated the from_slice* functions on the Set side too, And fixes all the signatures by replacing Unwraps with ?
This commit is contained in:
+9
-14
@@ -1744,11 +1744,10 @@ where
|
||||
) -> Result<RangeBoundsMap<I, K, V>, OverlapError> {
|
||||
let mut map = RangeBoundsMap::new();
|
||||
for (range_bounds, value) in slice {
|
||||
map.insert_strict(range_bounds, value).unwrap();
|
||||
map.insert_strict(range_bounds, value)?;
|
||||
}
|
||||
return Ok(map);
|
||||
}
|
||||
|
||||
/// Allocate a `RangeBoundsMap` and move the given (`RangeBounds`,
|
||||
/// `Value`) pairs from the slice into the map using
|
||||
/// [`RangeBoundsMap::insert_merge_touching()`].
|
||||
@@ -1777,17 +1776,16 @@ where
|
||||
#[trivial]
|
||||
pub fn from_slice_merge_touching<const N: usize>(
|
||||
slice: [(K, V); N],
|
||||
) -> Result<RangeBoundsMap<I, K, V>, OverlapError>
|
||||
) -> Result<RangeBoundsMap<I, K, V>, OverlapOrTryFromBoundsError>
|
||||
where
|
||||
K: TryFromBounds<I>,
|
||||
{
|
||||
let mut map = RangeBoundsMap::new();
|
||||
for (range_bounds, value) in slice {
|
||||
map.insert_merge_touching(range_bounds, value).unwrap();
|
||||
map.insert_merge_touching(range_bounds, value)?;
|
||||
}
|
||||
return Ok(map);
|
||||
}
|
||||
|
||||
/// Allocate a `RangeBoundsMap` and move the given (`RangeBounds`,
|
||||
/// `Value`) pairs from the slice into the map using
|
||||
/// [`RangeBoundsMap::insert_merge_overlapping()`].
|
||||
@@ -1816,17 +1814,16 @@ where
|
||||
#[trivial]
|
||||
pub fn from_slice_merge_overlapping<const N: usize>(
|
||||
slice: [(K, V); N],
|
||||
) -> Result<RangeBoundsMap<I, K, V>, OverlapError>
|
||||
) -> Result<RangeBoundsMap<I, K, V>, TryFromBoundsError>
|
||||
where
|
||||
K: TryFromBounds<I>,
|
||||
{
|
||||
let mut map = RangeBoundsMap::new();
|
||||
for (range_bounds, value) in slice {
|
||||
map.insert_merge_overlapping(range_bounds, value).unwrap();
|
||||
map.insert_merge_overlapping(range_bounds, value)?;
|
||||
}
|
||||
return Ok(map);
|
||||
}
|
||||
|
||||
/// Allocate a `RangeBoundsMap` and move the given (`RangeBounds`,
|
||||
/// `Value`) pairs from the slice into the map using
|
||||
/// [`RangeBoundsMap::insert_merge_touching_or_overlapping()`].
|
||||
@@ -1857,18 +1854,16 @@ where
|
||||
#[trivial]
|
||||
pub fn from_slice_merge_touching_or_overlapping<const N: usize>(
|
||||
slice: [(K, V); N],
|
||||
) -> Result<RangeBoundsMap<I, K, V>, OverlapError>
|
||||
) -> Result<RangeBoundsMap<I, K, V>, TryFromBoundsError>
|
||||
where
|
||||
K: TryFromBounds<I>,
|
||||
{
|
||||
let mut map = RangeBoundsMap::new();
|
||||
for (range_bounds, value) in slice {
|
||||
map.insert_merge_touching_or_overlapping(range_bounds, value)
|
||||
.unwrap();
|
||||
map.insert_merge_touching_or_overlapping(range_bounds, value)?;
|
||||
}
|
||||
return Ok(map);
|
||||
}
|
||||
|
||||
/// Allocate a `RangeBoundsMap` and move the given (`RangeBounds`,
|
||||
/// `Value`) pairs from the slice into the map using
|
||||
/// [`RangeBoundsMap::insert_overwrite()`].
|
||||
@@ -1897,14 +1892,14 @@ where
|
||||
#[trivial]
|
||||
pub fn from_slice_overwrite<const N: usize>(
|
||||
slice: [(K, V); N],
|
||||
) -> Result<RangeBoundsMap<I, K, V>, OverlapError>
|
||||
) -> Result<RangeBoundsMap<I, K, V>, TryFromBoundsError>
|
||||
where
|
||||
V: Clone,
|
||||
K: TryFromBounds<I>,
|
||||
{
|
||||
let mut map = RangeBoundsMap::new();
|
||||
for (range_bounds, value) in slice {
|
||||
map.insert_overwrite(range_bounds, value).unwrap();
|
||||
map.insert_overwrite(range_bounds, value)?;
|
||||
}
|
||||
return Ok(map);
|
||||
}
|
||||
|
||||
+153
-4
@@ -995,9 +995,8 @@ where
|
||||
/// from the slice into the set using
|
||||
/// [`RangeBoundsSet::insert_strict()`].
|
||||
///
|
||||
/// If any of the given `RangeBounds` overlap any of the other
|
||||
/// `RangeBounds` in the slice, then an [`OverlapError`] is
|
||||
/// returned.
|
||||
/// May return an `Err` while inserting. See
|
||||
/// [`RangeBoundsSet::insert_strict()`] for details.
|
||||
///
|
||||
/// # Panics
|
||||
///
|
||||
@@ -1019,7 +1018,157 @@ where
|
||||
) -> Result<RangeBoundsSet<I, K>, OverlapError> {
|
||||
let mut set = RangeBoundsSet::new();
|
||||
for range_bounds in slice {
|
||||
set.insert_strict(range_bounds).unwrap();
|
||||
set.insert_strict(range_bounds)?;
|
||||
}
|
||||
return Ok(set);
|
||||
}
|
||||
/// Allocate a `RangeBoundsSet` and move the given `RangeBounds`
|
||||
/// from the slice into the set using
|
||||
/// [`RangeBoundsSet::insert_merge_touching()`].
|
||||
///
|
||||
/// May return an `Err` while inserting. See
|
||||
/// [`RangeBoundsSet::insert_merge_touching()`] for details.
|
||||
///
|
||||
/// # Panics
|
||||
///
|
||||
/// Panics if any of the given `RangeBounds` is an invalid
|
||||
/// `RangeBounds`. See [`Invalid
|
||||
/// RangeBounds`](https://docs.rs/range_bounds_map/latest/range_bounds_map/index.html#Invalid-RangeBounds)
|
||||
/// for more details.
|
||||
///
|
||||
/// # Examples
|
||||
/// ```
|
||||
/// use range_bounds_map::{RangeBoundsSet, TryFromBoundsError};
|
||||
///
|
||||
/// let set = RangeBoundsSet::from_slice_merge_touching([
|
||||
/// 1..4,
|
||||
/// 4..8,
|
||||
/// 8..100,
|
||||
/// ])
|
||||
/// .unwrap();
|
||||
/// ```
|
||||
#[trivial]
|
||||
pub fn from_slice_merge_touching<const N: usize>(
|
||||
slice: [K; N],
|
||||
) -> Result<RangeBoundsSet<I, K>, OverlapOrTryFromBoundsError>
|
||||
where
|
||||
K: TryFromBounds<I>,
|
||||
{
|
||||
let mut set = RangeBoundsSet::new();
|
||||
for range_bounds in slice {
|
||||
set.insert_merge_touching(range_bounds)?;
|
||||
}
|
||||
return Ok(set);
|
||||
}
|
||||
/// Allocate a `RangeBoundsSet` and move the given `RangeBounds`
|
||||
/// from the slice into the set using
|
||||
/// [`RangeBoundsSet::insert_merge_overlapping()`].
|
||||
///
|
||||
/// May return an `Err` while inserting. See
|
||||
/// [`RangeBoundsSet::insert_merge_overlapping()`] for details.
|
||||
///
|
||||
/// # Panics
|
||||
///
|
||||
/// Panics if any of the given `RangeBounds` is an invalid
|
||||
/// `RangeBounds`. See [`Invalid
|
||||
/// RangeBounds`](https://docs.rs/range_bounds_map/latest/range_bounds_map/index.html#Invalid-RangeBounds)
|
||||
/// for more details.
|
||||
///
|
||||
/// # Examples
|
||||
/// ```
|
||||
/// use range_bounds_map::{RangeBoundsSet, TryFromBoundsError};
|
||||
///
|
||||
/// let set = RangeBoundsSet::from_slice_merge_overlapping([
|
||||
/// 1..4,
|
||||
/// 4..8,
|
||||
/// 8..100,
|
||||
/// ])
|
||||
/// .unwrap();
|
||||
/// ```
|
||||
#[trivial]
|
||||
pub fn from_slice_merge_overlapping<const N: usize>(
|
||||
slice: [K; N],
|
||||
) -> Result<RangeBoundsSet<I, K>, TryFromBoundsError>
|
||||
where
|
||||
K: TryFromBounds<I>,
|
||||
{
|
||||
let mut set = RangeBoundsSet::new();
|
||||
for range_bounds in slice {
|
||||
set.insert_merge_overlapping(range_bounds)?;
|
||||
}
|
||||
return Ok(set);
|
||||
}
|
||||
/// Allocate a `RangeBoundsSet` and move the given `RangeBounds`
|
||||
/// from the slice into the set using
|
||||
/// [`RangeBoundsSet::insert_merge_touching_or_overlapping()`].
|
||||
///
|
||||
/// May return an `Err` while inserting. See
|
||||
/// [`RangeBoundsSet::insert_merge_touching_or_overlapping()`] for details.
|
||||
///
|
||||
/// # Panics
|
||||
///
|
||||
/// Panics if any of the given `RangeBounds` is an invalid
|
||||
/// `RangeBounds`. See [`Invalid
|
||||
/// RangeBounds`](https://docs.rs/range_bounds_map/latest/range_bounds_map/index.html#Invalid-RangeBounds)
|
||||
/// for more details.
|
||||
///
|
||||
/// # Examples
|
||||
/// ```
|
||||
/// use range_bounds_map::{RangeBoundsSet, TryFromBoundsError};
|
||||
///
|
||||
/// let set =
|
||||
/// RangeBoundsSet::from_slice_merge_touching_or_overlapping([
|
||||
/// 1..4,
|
||||
/// 4..8,
|
||||
/// 8..100,
|
||||
/// ])
|
||||
/// .unwrap();
|
||||
/// ```
|
||||
#[trivial]
|
||||
pub fn from_slice_merge_touching_or_overlapping<const N: usize>(
|
||||
slice: [K; N],
|
||||
) -> Result<RangeBoundsSet<I, K>, TryFromBoundsError>
|
||||
where
|
||||
K: TryFromBounds<I>,
|
||||
{
|
||||
let mut set = RangeBoundsSet::new();
|
||||
for range_bounds in slice {
|
||||
set.insert_merge_touching_or_overlapping(range_bounds)?;
|
||||
}
|
||||
return Ok(set);
|
||||
}
|
||||
/// Allocate a `RangeBoundsSet` and move the given `RangeBounds`
|
||||
/// from the slice into the set using
|
||||
/// [`RangeBoundsSet::insert_overwrite()`].
|
||||
///
|
||||
/// May return an `Err` while inserting. See
|
||||
/// [`RangeBoundsSet::insert_overwrite()`] for details.
|
||||
///
|
||||
/// # Panics
|
||||
///
|
||||
/// Panics if any of the given `RangeBounds` is an invalid
|
||||
/// `RangeBounds`. See [`Invalid
|
||||
/// RangeBounds`](https://docs.rs/range_bounds_map/latest/range_bounds_map/index.html#Invalid-RangeBounds)
|
||||
/// for more details.
|
||||
///
|
||||
/// # Examples
|
||||
/// ```
|
||||
/// use range_bounds_map::{RangeBoundsSet, TryFromBoundsError};
|
||||
///
|
||||
/// let set =
|
||||
/// RangeBoundsSet::from_slice_overwrite([1..4, 4..8, 8..100])
|
||||
/// .unwrap();
|
||||
/// ```
|
||||
#[trivial]
|
||||
pub fn from_slice_overwrite<const N: usize>(
|
||||
slice: [K; N],
|
||||
) -> Result<RangeBoundsSet<I, K>, TryFromBoundsError>
|
||||
where
|
||||
K: TryFromBounds<I>,
|
||||
{
|
||||
let mut set = RangeBoundsSet::new();
|
||||
for range_bounds in slice {
|
||||
set.insert_overwrite(range_bounds)?;
|
||||
}
|
||||
return Ok(set);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user