Struct segmap::segment::Segment [−][src]
pub struct Segment<T> { /* fields omitted */ }
Expand description
Monotonically increasing segment, for use as a concrete range type in
[SegmentMap
].
Implementations
Construct a new segment from range bounds
If the range given is backwards (decreasing), it will be reversed
Weird Ranges
Oddly constructed ranges will be coerced to “sane” structure:
- Point ranges (where both start and end are bounded to the same value and at least one is included) will be coerced to (Included, Included)
Panics
Only one range is too strange to be included here. If you pass a point range with both the start and end excluded, this will panic, as the range is impossible to evaluate
let r = Segment::new(Bound::Included(0), Bound::Excluded(5)); assert_eq!(r.start_bound(), Bound::Included(&0)); assert_eq!(r.end_bound(), Bound::Excluded(&5));
See Also
Segment
also implements From
for all of the core::ops
range types,
so you may find it more convenient to construct a range like
Segment::from(a..b)
Construct a new [Range
] that spans all possible values
This is the same as Range::from(..)
.
Examples
let r = Segment::<u32>::full(); assert_eq!(r.start_bound(), Bound::Unbounded); assert_eq!(r.end_bound(), Bound::Unbounded);
Constructs a new point segement at the given value
Examples
let r = Segment::point(5); assert_eq!(r.start_bound(), Bound::Included(&5)); assert_eq!(r.end_bound(), Bound::Included(&5));
Get the start value of the range (if it is bounded)
Examples
let bounded = Segment::from(5..10); assert_eq!(bounded.start_value(), Some(&5)); let unbounded = Segment::from(..10); assert_eq!(unbounded.start_value(), None);
Get the end value of the range (if it is bounded)
Examples
let bounded = Segment::from(5..10); assert_eq!(bounded.end_value(), Some(&10)); let unbounded = Segment::from(5..); assert_eq!(unbounded.end_value(), None);
Converts from Segment<T>
to Segment<&T>
.
Many iterators from this crate return a Segment<&T>
instead of a
&Segment<T>
since bounds need to be constructed or adjusted. This allows
us to avoid clone
ing T
.
Check whether the range overlaps with another
Examples
// Overlapping Segments let a = Segment::from(0..10); let b = Segment::from(5..15); assert!(a.overlaps(&b)); // Touching Segments let a = Segment::from(0..10); let b = Segment::from(10..20); assert!(!a.overlaps(&b)); // Separate Segments let a = Segment::from(0..10); let b = Segment::from(15..20); assert!(!a.overlaps(&b));
See Also
Segment::touches
for overlapping OR adjacent ranges
Check whether the range touches another, either overlapping it or directly adjacent to it
Examples
// Overlapping Segments let a = Segment::from(0..10); let b = Segment::from(5..15); assert!(a.touches(&b)); // Touching Segments let a = Segment::from(0..10); let b = Segment::from(10..20); assert!(a.touches(&b)); // Separate Segments let a = Segment::from(0..10); let b = Segment::from(15..20); assert!(!a.touches(&b));
See Also
Segment::overlaps
for only overlapping ranges
Trait Implementations
Extends a collection with the contents of an iterator. Read more
extend_one
)Extends a collection with exactly one element.
extend_one
)Reserves capacity in a collection for the given number of additional elements. Read more
Insert all the items from iter
into self
.
NOTE: Inserted items will overwrite existing ranges in self
if
they overlap. If you don’t want to overwrite existing ranges, use
[extend_into_gaps
].
Clone is required for insertion, since we can’t guarantee elements in iter
are ordered or non-overlapping, so ranges may need to be split.
extend_one
)Extends a collection with exactly one element.
extend_one
)Reserves capacity in a collection for the given number of additional elements. Read more
Performs the conversion.
Performs the conversion.
Start index bound. Read more
1.35.0[src]fn contains<U>(&self, item: &U) -> bool where
T: PartialOrd<U>,
U: PartialOrd<T> + ?Sized,
fn contains<U>(&self, item: &U) -> bool where
T: PartialOrd<U>,
U: PartialOrd<T> + ?Sized,
Returns true
if item
is contained in the range. Read more
Start index bound. Read more
1.35.0[src]fn contains<U>(&self, item: &U) -> bool where
T: PartialOrd<U>,
U: PartialOrd<T> + ?Sized,
fn contains<U>(&self, item: &U) -> bool where
T: PartialOrd<U>,
U: PartialOrd<T> + ?Sized,
Returns true
if item
is contained in the range. Read more
Auto Trait Implementations
Blanket Implementations
Mutably borrows from an owned value. Read more