diff --git a/src/range_bounds_map.rs b/src/range_bounds_map.rs index e29843e..922b098 100644 --- a/src/range_bounds_map.rs +++ b/src/range_bounds_map.rs @@ -1738,6 +1738,56 @@ where } } +impl TryFrom<[(K, V); N]> for RangeBoundsMap +where + K: RangeBounds, + I: Ord + Clone, +{ + type Error = OverlapError; + #[trivial] + fn try_from(pairs: [(K, V); N]) -> Result { + let mut range_bounds_map = RangeBoundsMap::new(); + for (range_bounds, value) in pairs { + range_bounds_map.insert_strict(range_bounds, value)?; + } + + return Ok(range_bounds_map); + } +} +impl TryFrom> for RangeBoundsMap +where + K: RangeBounds, + I: Ord + Clone, +{ + type Error = OverlapError; + #[trivial] + fn try_from(pairs: Vec<(K, V)>) -> Result { + let mut range_bounds_map = RangeBoundsMap::new(); + for (range_bounds, value) in pairs { + range_bounds_map.insert_strict(range_bounds, value)?; + } + + return Ok(range_bounds_map); + } +} + +impl FromIterator<(K, V)> for RangeBoundsMap +where + K: RangeBounds, + I: Ord + Clone, +{ + #[trivial] + fn from_iter>(iter: T) -> Self { + let mut output = RangeBoundsMap::new(); + + for (range_bounds, value) in iter { + output.insert_strict(range_bounds, value).unwrap(); + } + + return output; + } +} + impl IntoIterator for RangeBoundsMap where K: RangeBounds, diff --git a/src/range_bounds_set.rs b/src/range_bounds_set.rs index ae28007..3c59edd 100644 --- a/src/range_bounds_set.rs +++ b/src/range_bounds_set.rs @@ -1016,6 +1016,55 @@ where } } +impl TryFrom<[K; N]> for RangeBoundsSet +where + K: RangeBounds, + I: Ord + Clone, +{ + type Error = OverlapError; + #[trivial] + fn try_from(pairs: [K; N]) -> Result { + let mut range_bounds_set = RangeBoundsSet::new(); + for range_bounds in pairs { + range_bounds_set.insert_strict(range_bounds)?; + } + + return Ok(range_bounds_set); + } +} +impl TryFrom> for RangeBoundsSet +where + K: RangeBounds, + I: Ord + Clone, +{ + type Error = OverlapError; + #[trivial] + fn try_from(pairs: Vec) -> Result { + let mut range_bounds_set = RangeBoundsSet::new(); + for range_bounds in pairs { + range_bounds_set.insert_strict(range_bounds)?; + } + + return Ok(range_bounds_set); + } +} + +impl FromIterator for RangeBoundsSet +where + K: RangeBounds, + I: Ord + Clone, +{ + #[trivial] + fn from_iter>(iter: T) -> Self { + let mut output = RangeBoundsSet::new(); + + for range_bounds in iter { + output.insert_strict(range_bounds).unwrap(); + } + + return output; + } +} impl IntoIterator for RangeBoundsSet where K: RangeBounds,