And while on the subject, it seems like the other 5 Range
types in std::ops
should impl TryFrom<(Bound, Bound)> too.
Does this seem reasonable?
Cheers, ripytide
And while on the subject, it seems like the other 5 Range
types in std::ops
should impl TryFrom<(Bound, Bound)> too.
Does this seem reasonable?
Cheers, ripytide
Can you say more about what you're trying to do where this would be useful?
It's possible you're looking for something like https://doc.rust-lang.org/std/slice/fn.range.html or impl RangeBounds
instead.
I am trying to create an instance of some type K: RangeBounds<I>
from two Bound
s that I happen to have. Hence it would be nice if Range
impl TryFrom<(Bound, Bound)>
Minimal example to attempt to flip then end_bound()
of some given RangeBound<I>
type:
use std::ops::{Bound, RangeBounds};
fn flip_end_bound<I, Q, K>(range_bounds: &Q) -> Option<K>
where
Q: RangeBounds<I>,
K: TryFrom<(Bound<I>, Bound<I>)>,
I: Clone,
{
let flipped_end_bound = match range_bounds.end_bound() {
Bound::Included(point) => Bound::Excluded(point),
Bound::Excluded(point) => Bound::Included(point),
Bound::Unbounded => Bound::Unbounded,
};
K::try_from((
range_bounds.start_bound().cloned(),
flipped_end_bound.cloned(),
))
.ok()
}
This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.