Skip to content

Commit

Permalink
adde conversion from the std Range and RangeInclusive
Browse files Browse the repository at this point in the history
  • Loading branch information
ripytide committed Dec 27, 2023
1 parent 92850de commit 90f0474
Showing 1 changed file with 30 additions and 1 deletion.
31 changes: 30 additions & 1 deletion src/inclusive_interval.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ along with discrete_range_map. If not, see <https://www.gnu.org/licenses/>.
//! yet. If you would still like the associated versions I would be happy to
//! add them as well, just open a PR/Issue.
use core::ops::{Bound, RangeBounds};
use core::ops::{Bound, Range, RangeBounds, RangeInclusive};

use serde::{Deserialize, Serialize};

Expand Down Expand Up @@ -115,6 +115,35 @@ where
self.end
}
}
impl<I> From<InclusiveInterval<I>> for RangeInclusive<I> {
fn from(value: InclusiveInterval<I>) -> Self {
value.start..=value.end
}
}
impl<I> From<RangeInclusive<I>> for InclusiveInterval<I>
where
I: PointType,
{
fn from(value: RangeInclusive<I>) -> Self {
ii(*value.start(), *value.end())
}
}
impl<I> From<InclusiveInterval<I>> for Range<I>
where
I: PointType,
{
fn from(value: InclusiveInterval<I>) -> Self {
value.start..value.end.up().unwrap()
}
}
impl<I> From<Range<I>> for InclusiveInterval<I>
where
I: PointType,
{
fn from(value: Range<I>) -> Self {
ie(value.start, value.end)
}
}

/// Create an new Unbounded-Unbounded interval.
///
Expand Down

0 comments on commit 90f0474

Please sign in to comment.