diff --git a/README.md b/README.md
index 6808e64..7c302a8 100644
--- a/README.md
+++ b/README.md
@@ -22,14 +22,14 @@ based on [`RangeBoundsMap`].
```rust
use range_bounds_map::RangeBoundsMap;
-let mut range_bounds_map = RangeBoundsMap::new();
+let mut map = RangeBoundsMap::new();
-range_bounds_map.insert_strict(0..5, true);
-range_bounds_map.insert_strict(5..10, false);
+map.insert_strict(0..5, true);
+map.insert_strict(5..10, false);
-assert_eq!(range_bounds_map.overlaps(&(-2..12)), true);
-assert_eq!(range_bounds_map.contains_point(&20), false);
-assert_eq!(range_bounds_map.contains_point(&5), true);
+assert_eq!(map.overlaps(&(-2..12)), true);
+assert_eq!(map.contains_point(&20), false);
+assert_eq!(map.contains_point(&5), true);
```
## Example using a custom [`RangeBounds`] type
diff --git a/src/lib.rs b/src/lib.rs
index fc4c937..546a2ed 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -30,14 +30,14 @@ along with range_bounds_map. If not, see .
//! ```rust
//! use range_bounds_map::RangeBoundsMap;
//!
-//! let mut range_bounds_map = RangeBoundsMap::new();
+//! let mut map = RangeBoundsMap::new();
//!
-//! range_bounds_map.insert_strict(0..5, true);
-//! range_bounds_map.insert_strict(5..10, false);
+//! map.insert_strict(0..5, true);
+//! map.insert_strict(5..10, false);
//!
-//! assert_eq!(range_bounds_map.overlaps(&(-2..12)), true);
-//! assert_eq!(range_bounds_map.contains_point(&20), false);
-//! assert_eq!(range_bounds_map.contains_point(&5), true);
+//! assert_eq!(map.overlaps(&(-2..12)), true);
+//! assert_eq!(map.contains_point(&20), false);
+//! assert_eq!(map.contains_point(&5), true);
//! ```
//!
//! ## Example using a custom [`RangeBounds`] type
diff --git a/src/range_bounds_map.rs b/src/range_bounds_map.rs
index 34305b7..e6693c7 100644
--- a/src/range_bounds_map.rs
+++ b/src/range_bounds_map.rs
@@ -163,7 +163,7 @@ pub struct OverlapError;
/// ```
/// use range_bounds_map::{RangeBoundsMap, TryFromBoundsError};
///
-/// let mut range_bounds_map =
+/// let mut map =
/// RangeBoundsMap::from_slice_strict([(2..8, true)]).unwrap();
///
/// assert!(range_bounds_map.cut(&(4..=6)).is_err());
@@ -245,7 +245,7 @@ pub struct OverlapError;
/// }
/// }
///
-/// let mut range_bounds_map = RangeBoundsMap::from_slice_strict([(
+/// let mut map = RangeBoundsMap::from_slice_strict([(
/// MultiBounds::Inclusive(2, 4),
/// true,
/// )])
@@ -285,7 +285,7 @@ where
///
/// use range_bounds_map::RangeBoundsMap;
///
- /// let range_bounds_map: RangeBoundsMap, bool> =
+ /// let map: RangeBoundsMap, bool> =
/// RangeBoundsMap::new();
/// ```
#[trivial]
@@ -301,7 +301,7 @@ where
/// ```
/// use range_bounds_map::RangeBoundsMap;
///
- /// let mut range_bounds_map = RangeBoundsMap::new();
+ /// let mut map = RangeBoundsMap::new();
///
/// assert_eq!(range_bounds_map.len(), 0);
/// range_bounds_map.insert_strict(0..1, false).unwrap();
@@ -319,7 +319,7 @@ where
/// ```
/// use range_bounds_map::RangeBoundsMap;
///
- /// let mut range_bounds_map = RangeBoundsMap::new();
+ /// let mut map = RangeBoundsMap::new();
///
/// assert_eq!(range_bounds_map.is_empty(), true);
/// range_bounds_map.insert_strict(0..1, false).unwrap();
@@ -334,8 +334,8 @@ where
/// modifying other entries.
///
/// If the given `RangeBounds` overlaps one or more `RangeBounds`
- /// already in the map rather than just touching, then an
- /// [`OverlapError`] is returned and the map is not updated.
+ /// already in the map, then an [`OverlapError`] is returned and
+ /// the map is not updated.
///
/// # Panics
///
@@ -348,7 +348,7 @@ where
/// ```
/// use range_bounds_map::{OverlapError, RangeBoundsMap};
///
- /// let mut range_bounds_map = RangeBoundsMap::new();
+ /// let mut map = RangeBoundsMap::new();
///
/// assert_eq!(range_bounds_map.insert_strict(5..10, 9), Ok(()));
/// assert_eq!(
@@ -393,7 +393,7 @@ where
/// ```
/// use range_bounds_map::RangeBoundsMap;
///
- /// let mut range_bounds_map = RangeBoundsMap::new();
+ /// let mut map = RangeBoundsMap::new();
///
/// range_bounds_map.insert_strict(5..10, false);
///
@@ -426,7 +426,7 @@ where
/// ```
/// use range_bounds_map::RangeBoundsMap;
///
- /// let range_bounds_map = RangeBoundsMap::from_slice_strict([
+ /// let map = RangeBoundsMap::from_slice_strict([
/// (1..4, false),
/// (4..8, true),
/// (8..100, false),
@@ -501,7 +501,7 @@ where
/// ```
/// use range_bounds_map::RangeBoundsMap;
///
- /// let range_bounds_map = RangeBoundsMap::from_slice_strict([
+ /// let map = RangeBoundsMap::from_slice_strict([
/// (1..4, false),
/// (4..8, true),
/// (8..100, false),
@@ -524,7 +524,7 @@ where
/// ```
/// use range_bounds_map::RangeBoundsMap;
///
- /// let range_bounds_map = RangeBoundsMap::from_slice_strict([
+ /// let map = RangeBoundsMap::from_slice_strict([
/// (1..4, false),
/// (4..8, true),
/// (8..100, false),
@@ -547,7 +547,7 @@ where
/// ```
/// use range_bounds_map::RangeBoundsMap;
///
- /// let mut range_bounds_map =
+ /// let mut map =
/// RangeBoundsMap::from_slice_strict([(1..4, false)]).unwrap();
///
/// if let Some(x) = range_bounds_map.get_at_point_mut(&2) {
@@ -577,7 +577,7 @@ where
/// ```
/// use range_bounds_map::RangeBoundsMap;
///
- /// let range_bounds_map = RangeBoundsMap::from_slice_strict([
+ /// let map = RangeBoundsMap::from_slice_strict([
/// (1..4, false),
/// (4..8, true),
/// (8..100, false),
@@ -612,7 +612,7 @@ where
/// ```
/// use range_bounds_map::RangeBoundsMap;
///
- /// let range_bounds_map = RangeBoundsMap::from_slice_strict([
+ /// let map = RangeBoundsMap::from_slice_strict([
/// (1..4, false),
/// (4..8, true),
/// (8..100, false),
@@ -646,7 +646,7 @@ where
/// ```
/// use range_bounds_map::RangeBoundsMap;
///
- /// let mut range_bounds_map = RangeBoundsMap::from_slice_strict([
+ /// let mut map = RangeBoundsMap::from_slice_strict([
/// (1..4, false),
/// (4..8, true),
/// (8..100, false),
@@ -910,7 +910,7 @@ where
///
/// use range_bounds_map::RangeBoundsMap;
///
- /// let range_bounds_map = RangeBoundsMap::from_slice_strict([
+ /// let map = RangeBoundsMap::from_slice_strict([
/// (1..3, false),
/// (5..7, true),
/// (9..100, false),
@@ -1011,7 +1011,7 @@ where
///
/// use range_bounds_map::{RangeBoundsMap, TryFromBoundsError};
///
- /// let range_bounds_map = RangeBoundsMap::from_slice_strict([
+ /// let map = RangeBoundsMap::from_slice_strict([
/// (1..3, false),
/// (5..7, true),
/// (9..100, false),
@@ -1054,7 +1054,7 @@ where
/// ```
/// use range_bounds_map::RangeBoundsMap;
///
- /// let range_bounds_map = RangeBoundsMap::from_slice_strict([
+ /// let map = RangeBoundsMap::from_slice_strict([
/// (1..3, false),
/// (5..8, true),
/// (8..100, false),
@@ -1090,9 +1090,8 @@ where
/// `RangeBounds` is returned.
///
/// If the given `RangeBounds` overlaps one or more `RangeBounds`
- /// already in the map rather than just touching, then an
- /// [`OverlapError`] is returned and the map is not updated.
- /// `RangeBounds` is returned.
+ /// already in the map, then an [`OverlapError`] is returned and
+ /// the map is not updated.
///
/// If the merged `RangeBounds` cannot be created with the
/// [`TryFromBounds`] trait then a [`TryFromBoundsError`] will be
@@ -1111,7 +1110,7 @@ where
/// OverlapError, OverlapOrTryFromBoundsError, RangeBoundsMap,
/// };
///
- /// let mut range_bounds_map =
+ /// let mut map =
/// RangeBoundsMap::from_slice_strict([(1..4, false)]).unwrap();
///
/// // Touching
@@ -1241,7 +1240,7 @@ where
/// ```
/// use range_bounds_map::RangeBoundsMap;
///
- /// let mut range_bounds_map =
+ /// let mut map =
/// RangeBoundsMap::from_slice_strict([(1..4, false)]).unwrap();
///
/// // Touching
@@ -1346,7 +1345,7 @@ where
/// ```
/// use range_bounds_map::RangeBoundsMap;
///
- /// let mut range_bounds_map =
+ /// let mut map =
/// RangeBoundsMap::from_slice_strict([(1..4, false)]).unwrap();
///
/// // Touching
@@ -1430,7 +1429,7 @@ where
/// ```
/// use range_bounds_map::RangeBoundsMap;
///
- /// let mut range_bounds_map =
+ /// let mut map =
/// RangeBoundsMap::from_slice_strict([(2..8, false)]).unwrap();
///
/// assert_eq!(range_bounds_map.insert_overwrite(4..6, true), Ok(()));
@@ -1463,7 +1462,7 @@ where
/// ```
/// use range_bounds_map::RangeBoundsMap;
///
- /// let range_bounds_map = RangeBoundsMap::from_slice_strict([
+ /// let map = RangeBoundsMap::from_slice_strict([
/// (1..4, false),
/// (4..8, true),
/// (8..100, false),
@@ -1487,7 +1486,7 @@ where
/// ```
/// use range_bounds_map::RangeBoundsMap;
///
- /// let range_bounds_map = RangeBoundsMap::from_slice_strict([
+ /// let map = RangeBoundsMap::from_slice_strict([
/// (1..4, false),
/// (4..8, true),
/// (8..100, false),
@@ -1645,7 +1644,7 @@ where
///
/// use range_bounds_map::RangeBoundsMap;
///
- /// let range_bounds_map = RangeBoundsMap::from_slice_strict([
+ /// let map = RangeBoundsMap::from_slice_strict([
/// (1..4, false),
/// (4..8, true),
/// (8..100, false),
@@ -1707,7 +1706,7 @@ where
/// ```
/// use range_bounds_map::{RangeBoundsMap, TryFromBoundsError};
///
- /// let range_bounds_map = RangeBoundsMap::from_slice_strict([
+ /// let map = RangeBoundsMap::from_slice_strict([
/// (1..4, false),
/// (4..8, true),
/// (8..100, false),
@@ -1745,9 +1744,32 @@ where
})
}
- /// Allocate a `RangeBoundsMap` and move the given `RangeBounds`
- /// in the slice into the map using
- /// [`RangeBoundsMap::insert_strict()`].
+ /// Allocate a `RangeBoundsMap` and move the given (`RangeBounds`,
+ /// `Value`) pairs from the slice into the map using
+ /// [`RangeBoundsMap::insert_strict()`].
+ ///
+ /// If any of the given `RangeBounds` overlap any of the other
+ /// `RangeBounds` in the slice, then an [`OverlapError`] is
+ /// returned.
+ ///
+ /// # 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::{RangeBoundsMap, TryFromBoundsError};
+ ///
+ /// let map = RangeBoundsMap::from_slice_strict([
+ /// (1..4, false),
+ /// (4..8, true),
+ /// (8..100, false),
+ /// ])
+ /// .unwrap();
+ /// ```
#[trivial]
pub fn from_slice_strict(
slice: [(K, V); N],
@@ -1867,13 +1889,12 @@ where
where
A: MapAccess<'de>,
{
- let mut range_bounds_map = RangeBoundsMap::new();
+ let mut map = RangeBoundsMap::new();
while let Some((range_bounds, value)) = access.next_entry()? {
- range_bounds_map
- .insert_strict(range_bounds, value)
+ map.insert_strict(range_bounds, value)
.map_err(|_| serde::de::Error::custom("RangeBounds overlap"))?;
}
- Ok(range_bounds_map)
+ Ok(map)
}
}
@@ -2283,15 +2304,15 @@ mod tests {
//case one
for overlap_range in all_valid_test_bounds() {
for inside_range in all_valid_test_bounds() {
- let mut range_bounds_map = RangeBoundsMap::new();
- range_bounds_map.insert_strict(inside_range, ()).unwrap();
+ let mut map = RangeBoundsMap::new();
+ map.insert_strict(inside_range, ()).unwrap();
let mut expected_overlapping = Vec::new();
if overlaps(&overlap_range, &inside_range) {
expected_overlapping.push(inside_range);
}
- let overlapping = range_bounds_map
+ let overlapping = map
.overlapping(&overlap_range)
.map(|(key, _)| key)
.copied()
@@ -2312,9 +2333,9 @@ mod tests {
for (inside_range1, inside_range2) in
all_non_overlapping_test_bound_pairs()
{
- let mut range_bounds_map = RangeBoundsMap::new();
- range_bounds_map.insert_strict(inside_range1, ()).unwrap();
- range_bounds_map.insert_strict(inside_range2, ()).unwrap();
+ let mut map = RangeBoundsMap::new();
+ map.insert_strict(inside_range1, ()).unwrap();
+ map.insert_strict(inside_range2, ()).unwrap();
let mut expected_overlapping = Vec::new();
if overlaps(&overlap_range, &inside_range1) {
@@ -2332,7 +2353,7 @@ mod tests {
}
}
- let overlapping = range_bounds_map
+ let overlapping = map
.overlapping(&overlap_range)
.map(|(key, _)| key)
.copied()
@@ -2365,14 +2386,13 @@ mod tests {
//case one
for overlap_range in all_valid_test_bounds() {
for inside_range in all_valid_test_bounds() {
- let mut range_bounds_map = RangeBoundsMap::new();
- range_bounds_map.insert_strict(inside_range, ()).unwrap();
+ let mut map = RangeBoundsMap::new();
+ map.insert_strict(inside_range, ()).unwrap();
let mut result = RangeBoundsMap::new();
- for (resulting_range_bounds, resulting_value) in
- range_bounds_map
- .overlapping_trimmed(&overlap_range)
- .map(|(key, value)| (cloned_bounds(key), value.clone()))
+ for (resulting_range_bounds, resulting_value) in map
+ .overlapping_trimmed(&overlap_range)
+ .map(|(key, value)| (cloned_bounds(key), value.clone()))
{
result
.insert_strict(resulting_range_bounds, resulting_value)
@@ -2393,15 +2413,14 @@ mod tests {
for (inside_range1, inside_range2) in
all_non_overlapping_test_bound_pairs()
{
- let mut range_bounds_map = RangeBoundsMap::new();
- range_bounds_map.insert_strict(inside_range1, ()).unwrap();
- range_bounds_map.insert_strict(inside_range2, ()).unwrap();
+ let mut map = RangeBoundsMap::new();
+ map.insert_strict(inside_range1, ()).unwrap();
+ map.insert_strict(inside_range2, ()).unwrap();
let mut result = RangeBoundsMap::new();
- for (resulting_range_bounds, resulting_value) in
- range_bounds_map
- .overlapping_trimmed(&overlap_range)
- .map(|(key, value)| (cloned_bounds(key), value.clone()))
+ for (resulting_range_bounds, resulting_value) in map
+ .overlapping_trimmed(&overlap_range)
+ .map(|(key, value)| (cloned_bounds(key), value.clone()))
{
result
.insert_strict(resulting_range_bounds, resulting_value)
diff --git a/src/range_bounds_set.rs b/src/range_bounds_set.rs
index 9d934be..94a7c7a 100644
--- a/src/range_bounds_set.rs
+++ b/src/range_bounds_set.rs
@@ -130,8 +130,7 @@ where
///
/// use range_bounds_map::RangeBoundsSet;
///
- /// let range_bounds_set: RangeBoundsSet> =
- /// RangeBoundsSet::new();
+ /// let set: RangeBoundsSet> = RangeBoundsSet::new();
/// ```
#[trivial]
pub fn new() -> Self {
@@ -146,7 +145,7 @@ where
/// ```
/// use range_bounds_map::RangeBoundsSet;
///
- /// let mut range_bounds_set = RangeBoundsSet::new();
+ /// let mut set = RangeBoundsSet::new();
///
/// assert_eq!(range_bounds_set.len(), 0);
/// range_bounds_set.insert_strict(0..1).unwrap();
@@ -164,7 +163,7 @@ where
/// ```
/// use range_bounds_map::RangeBoundsSet;
///
- /// let mut range_bounds_set = RangeBoundsSet::new();
+ /// let mut set = RangeBoundsSet::new();
///
/// assert_eq!(range_bounds_set.is_empty(), true);
/// range_bounds_set.insert_strict(0..1).unwrap();
@@ -179,8 +178,8 @@ where
/// `RangeBounds` in the set.
///
/// If the given `RangeBounds` overlaps one or more `RangeBounds`
- /// already in the set rather than just touching, then an
- /// [`OverlapError`] is returned and the set is not updated.
+ /// already in the set, then an [`OverlapError`] is returned and
+ /// the set is not updated.
///
/// # Panics
///
@@ -193,7 +192,7 @@ where
/// ```
/// use range_bounds_map::{OverlapError, RangeBoundsSet};
///
- /// let mut range_bounds_set = RangeBoundsSet::new();
+ /// let mut set = RangeBoundsSet::new();
///
/// assert_eq!(range_bounds_set.insert_strict(5..10), Ok(()));
/// assert_eq!(
@@ -224,7 +223,7 @@ where
/// ```
/// use range_bounds_map::RangeBoundsSet;
///
- /// let mut range_bounds_set = RangeBoundsSet::new();
+ /// let mut set = RangeBoundsSet::new();
///
/// range_bounds_set.insert_strict(5..10);
///
@@ -256,9 +255,8 @@ where
/// ```
/// use range_bounds_map::RangeBoundsSet;
///
- /// let range_bounds_set =
- /// RangeBoundsSet::from_slice_strict([1..4, 4..8, 8..100])
- /// .unwrap();
+ /// let set = RangeBoundsSet::from_slice_strict([1..4, 4..8, 8..100])
+ /// .unwrap();
///
/// let mut overlapping = range_bounds_set.overlapping(&(2..8));
///
@@ -285,9 +283,8 @@ where
/// ```
/// use range_bounds_map::RangeBoundsSet;
///
- /// let range_bounds_set =
- /// RangeBoundsSet::from_slice_strict([1..4, 4..8, 8..100])
- /// .unwrap();
+ /// let set = RangeBoundsSet::from_slice_strict([1..4, 4..8, 8..100])
+ /// .unwrap();
///
/// assert_eq!(range_bounds_set.get_at_point(&3), Some(&(1..4)));
/// assert_eq!(range_bounds_set.get_at_point(&4), Some(&(4..8)));
@@ -305,9 +302,8 @@ where
/// ```
/// use range_bounds_map::RangeBoundsSet;
///
- /// let range_bounds_set =
- /// RangeBoundsSet::from_slice_strict([1..4, 4..8, 8..100])
- /// .unwrap();
+ /// let set = RangeBoundsSet::from_slice_strict([1..4, 4..8, 8..100])
+ /// .unwrap();
///
/// assert_eq!(range_bounds_set.contains_point(&3), true);
/// assert_eq!(range_bounds_set.contains_point(&4), true);
@@ -325,9 +321,8 @@ where
/// ```
/// use range_bounds_map::RangeBoundsSet;
///
- /// let range_bounds_set =
- /// RangeBoundsSet::from_slice_strict([1..4, 4..8, 8..100])
- /// .unwrap();
+ /// let set = RangeBoundsSet::from_slice_strict([1..4, 4..8, 8..100])
+ /// .unwrap();
///
/// let mut iter = range_bounds_set.iter();
///
@@ -355,7 +350,7 @@ where
/// ```
/// use range_bounds_map::RangeBoundsSet;
///
- /// let mut range_bounds_set =
+ /// let mut set =
/// RangeBoundsSet::from_slice_strict([1..4, 4..8, 8..100])
/// .unwrap();
///
@@ -501,9 +496,8 @@ where
///
/// use range_bounds_map::RangeBoundsSet;
///
- /// let range_bounds_set =
- /// RangeBoundsSet::from_slice_strict([1..3, 5..7, 9..100])
- /// .unwrap();
+ /// let set = RangeBoundsSet::from_slice_strict([1..3, 5..7, 9..100])
+ /// .unwrap();
///
/// let mut gaps = range_bounds_set.gaps(&(2..));
///
@@ -543,9 +537,8 @@ where
///
/// use range_bounds_map::{RangeBoundsSet, TryFromBoundsError};
///
- /// let range_bounds_set =
- /// RangeBoundsSet::from_slice_strict([1..3, 5..7, 9..100])
- /// .unwrap();
+ /// let set = RangeBoundsSet::from_slice_strict([1..3, 5..7, 9..100])
+ /// .unwrap();
///
/// let mut gaps_same = range_bounds_set.gaps_same(&(2..));
///
@@ -580,9 +573,8 @@ where
/// ```
/// use range_bounds_map::RangeBoundsSet;
///
- /// let range_bounds_set =
- /// RangeBoundsSet::from_slice_strict([1..3, 5..8, 8..100])
- /// .unwrap();
+ /// let set = RangeBoundsSet::from_slice_strict([1..3, 5..8, 8..100])
+ /// .unwrap();
///
/// assert_eq!(range_bounds_set.contains_range_bounds(&(1..3)), true);
/// assert_eq!(
@@ -609,8 +601,8 @@ where
/// `RangeBounds` is returned.
///
/// If the given `RangeBounds` overlaps one or more `RangeBounds`
- /// already in the set rather than just touching, then an
- /// [`OverlapError`] is returned and the set is not updated.
+ /// already in the set, then an [`OverlapError`] is returned and
+ /// the set is not updated.
///
/// If the merged `RangeBounds` cannot be created with the
/// [`TryFromBounds`] trait then a [`TryFromBoundsError`] will be
@@ -629,8 +621,7 @@ where
/// OverlapError, OverlapOrTryFromBoundsError, RangeBoundsSet,
/// };
///
- /// let mut range_bounds_set =
- /// RangeBoundsSet::from_slice_strict([1..4]).unwrap();
+ /// let mut set = RangeBoundsSet::from_slice_strict([1..4]).unwrap();
///
/// // Touching
/// assert_eq!(
@@ -687,8 +678,7 @@ where
/// ```
/// use range_bounds_map::RangeBoundsSet;
///
- /// let mut range_bounds_set =
- /// RangeBoundsSet::from_slice_strict([1..4]).unwrap();
+ /// let mut set = RangeBoundsSet::from_slice_strict([1..4]).unwrap();
///
/// // Touching
/// assert_eq!(
@@ -745,8 +735,7 @@ where
/// ```
/// use range_bounds_map::RangeBoundsSet;
///
- /// let mut range_bounds_set =
- /// RangeBoundsSet::from_slice_strict([1..4]).unwrap();
+ /// let mut set = RangeBoundsSet::from_slice_strict([1..4]).unwrap();
///
/// // Touching
/// assert_eq!(
@@ -804,8 +793,7 @@ where
/// ```
/// use range_bounds_map::RangeBoundsSet;
///
- /// let mut range_bounds_set =
- /// RangeBoundsSet::from_slice_strict([2..8]).unwrap();
+ /// let mut set = RangeBoundsSet::from_slice_strict([2..8]).unwrap();
///
/// assert_eq!(range_bounds_set.insert_overwrite(4..6), Ok(()));
///
@@ -831,9 +819,8 @@ where
/// ```
/// use range_bounds_map::RangeBoundsSet;
///
- /// let range_bounds_set =
- /// RangeBoundsSet::from_slice_strict([1..4, 4..8, 8..100])
- /// .unwrap();
+ /// let set = RangeBoundsSet::from_slice_strict([1..4, 4..8, 8..100])
+ /// .unwrap();
///
/// assert_eq!(range_bounds_set.first(), Some(&(1..4)));
/// ```
@@ -848,9 +835,8 @@ where
/// ```
/// use range_bounds_map::RangeBoundsSet;
///
- /// let range_bounds_set =
- /// RangeBoundsSet::from_slice_strict([1..4, 4..8, 8..100])
- /// .unwrap();
+ /// let set = RangeBoundsSet::from_slice_strict([1..4, 4..8, 8..100])
+ /// .unwrap();
///
/// assert_eq!(range_bounds_set.last(), Some(&(8..100)));
/// ```
@@ -970,9 +956,8 @@ where
///
/// use range_bounds_map::RangeBoundsSet;
///
- /// let range_bounds_set =
- /// RangeBoundsSet::from_slice_strict([1..4, 4..8, 8..100])
- /// .unwrap();
+ /// let set = RangeBoundsSet::from_slice_strict([1..4, 4..8, 8..100])
+ /// .unwrap();
///
/// let mut overlapping_trimmed =
/// range_bounds_set.overlapping_trimmed(&(2..20));
@@ -1012,9 +997,8 @@ where
/// ```
/// use range_bounds_map::{RangeBoundsSet, TryFromBoundsError};
///
- /// let range_bounds_set =
- /// RangeBoundsSet::from_slice_strict([1..4, 4..8, 8..100])
- /// .unwrap();
+ /// let set = RangeBoundsSet::from_slice_strict([1..4, 4..8, 8..100])
+ /// .unwrap();
///
/// let mut overlapping_trimmed_same =
/// range_bounds_set.overlapping_trimmed_same(&(2..=20));
@@ -1042,8 +1026,27 @@ where
}
/// Allocate a `RangeBoundsSet` and move the given `RangeBounds`
- /// in the slice into the set using
- /// [`RangeBoundsMap::insert_strict()`].
+ /// 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.
+ ///
+ /// # 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_strict([1..4, 4..8, 8..100])
+ /// .unwrap();
+ /// ```
#[trivial]
pub fn from_slice_strict(
slice: [K; N],
@@ -1158,13 +1161,12 @@ where
where
A: SeqAccess<'de>,
{
- let mut range_bounds_set = RangeBoundsSet::new();
+ let mut set = RangeBoundsSet::new();
while let Some(range_bounds) = access.next_element()? {
- range_bounds_set
- .insert_strict(range_bounds)
+ set.insert_strict(range_bounds)
.map_err(|_| serde::de::Error::custom("RangeBounds overlap"))?;
}
- Ok(range_bounds_set)
+ Ok(set)
}
}