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 cloneing 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

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

Trait Implementations

Returns a copy of the value. Read more

Performs copy-assignment from source. Read more

Formats the value using the given formatter. Read more

Extends a collection with the contents of an iterator. Read more

🔬 This is a nightly-only experimental API. (extend_one)

Extends a collection with exactly one element.

🔬 This is a nightly-only experimental API. (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.

🔬 This is a nightly-only experimental API. (extend_one)

Extends a collection with exactly one element.

🔬 This is a nightly-only experimental API. (extend_one)

Reserves capacity in a collection for the given number of additional elements. Read more

Performs the conversion.

Performs the conversion.

Performs the conversion.

Performs the conversion.

Performs the conversion.

Performs the conversion.

Performs the conversion.

Feeds this value into the given Hasher. Read more

Feeds a slice of this type into the given Hasher. Read more

This method tests for self and other values to be equal, and is used by ==. Read more

This method tests for !=.

Start index bound. Read more

End index bound. Read more

Returns true if item is contained in the range. Read more

Start index bound. Read more

End index bound. Read more

Returns true if item is contained in the range. Read more

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Performs the conversion.

Performs the conversion.

The resulting type after obtaining ownership.

Creates owned data from borrowed data, usually by cloning. Read more

🔬 This is a nightly-only experimental API. (toowned_clone_into)

recently added

Uses borrowed data to replace owned data, usually by cloning. Read more

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.