Enum range_compare::RangeCmpResult
source · pub enum RangeCmpResult<T> {
CompletelyTheSame,
NotIncludedBelow,
NotIncludedAbove,
RangeEmpty,
CompletelyIncluded {
other_before: Range<T>,
other_after: Range<T>,
overlapping_part: Range<T>,
},
EndIncluded {
other_after: Range<T>,
original_part_which_is_not_included: Range<T>,
overlapping_part: Range<T>,
},
StartIncluded {
other_before: Range<T>,
original_part_which_is_not_included: Range<T>,
overlapping_part: Range<T>,
},
MiddleIncluded {
overlapping_part: Range<T>,
original_before_not_included: Range<T>,
original_after_not_included: Range<T>,
},
SameStartOriginalShorter {
overlapping_part: Range<T>,
other_after_not_included: Range<T>,
},
SameStartOtherShorter {
overlapping_part: Range<T>,
original_after_not_included: Range<T>,
},
SameEndOriginalShorter {
overlapping_part: Range<T>,
other_before_not_included: Range<T>,
},
SameEndOtherShorter {
overlapping_part: Range<T>,
original_before_not_included: Range<T>,
},
}
Expand description
Result of the comparison of two ranges
This enum contains all possible results of the comparison of two ranges.
Variants§
CompletelyTheSame
The ranges have the same start
and end
values
use range_compare::{RangeExt, RangeCmpResult};
use std::ops::Range;
let range1 = 2..10;
let range2 = 2..10;
let result = range1.compare(&range2);
assert_eq!(result, RangeCmpResult::CompletelyTheSame);
NotIncludedBelow
The ranges are not overlapping and the range is below the other one
use range_compare::{RangeExt, RangeCmpResult};
use std::ops::Range;
let range1 = 2..10;
let range2 = 11..15;
let result = range1.compare(&range2);
assert_eq!(result, RangeCmpResult::NotIncludedBelow);
NotIncludedAbove
The ranges are not overlapping and the range is above the other one
use range_compare::{RangeExt, RangeCmpResult};
use std::ops::Range;
let range1 = 11..15;
let range2 = 2..10;
let result = range1.compare(&range2);
assert_eq!(result, RangeCmpResult::NotIncludedAbove);
RangeEmpty
One range is empty
use range_compare::{RangeExt, RangeCmpResult};
use std::ops::Range;
let range1 = 2..2;
let range2 = 5..15;
let result = range1.compare(&range2);
assert_eq!(result, RangeCmpResult::RangeEmpty);
CompletelyIncluded
The range is completely included in the other one
use range_compare::{RangeExt, RangeCmpResult};
use std::ops::Range;
let range1 = 5..7;
let range2 = 1..11;
let result = range1.compare(&range2);
assert_eq!(
result,
RangeCmpResult::CompletelyIncluded {
other_before: 1..5,
other_after: 7..11,
overlapping_part: 5..7,
}
);
EndIncluded
Fields
The end of the range is included in the other one
use range_compare::{RangeExt, RangeCmpResult};
use std::ops::Range;
let range1 = 1..9;
let range2 = 7..10;
let result = range1.compare(&range2);
assert_eq!(
result,
RangeCmpResult::EndIncluded {
other_after: 9..10,
original_part_which_is_not_included: 1..7,
overlapping_part: 7..9,
}
);
StartIncluded
Fields
The start of the range is included in the other one
use range_compare::{RangeExt, RangeCmpResult};
use std::ops::Range;
let range1 = 4..15;
let range2 = 1..9;
let result = range1.compare(&range2);
assert_eq!(
result,
RangeCmpResult::StartIncluded {
other_before: 1..4,
original_part_which_is_not_included: 9..15,
overlapping_part: 4..9,
}
);
MiddleIncluded
Fields
The middle of the range is included in the other one
use range_compare::{RangeExt, RangeCmpResult};
use std::ops::Range;
let range1 = 1..20;
let range2 = 4..15;
let result = range1.compare(&range2);
assert_eq!(
result,
RangeCmpResult::MiddleIncluded {
overlapping_part: 4..15,
original_before_not_included: 1..4,
original_after_not_included: 15..20,
}
);
SameStartOriginalShorter
The start of the range is the same as the start of the other range and the range is shorter
use range_compare::{RangeExt, RangeCmpResult};
use std::ops::Range;
let range1 = 1..10;
let range2 = 1..15;
let result = range1.compare(&range2);
assert_eq!(
result,
RangeCmpResult::SameStartOriginalShorter {
overlapping_part: 1..10,
other_after_not_included: 10..15,
}
);
SameStartOtherShorter
The start of the range is the same as the start of the other range and the other range is shorter
use range_compare::{RangeExt, RangeCmpResult};
use std::ops::Range;
let range1 = 1..15;
let range2 = 1..10;
let result = range1.compare(&range2);
assert_eq!(
result,
RangeCmpResult::SameStartOtherShorter {
overlapping_part: 1..10,
original_after_not_included: 10..15,
}
);
SameEndOriginalShorter
The end of the range is the same as the end of the other range and the range is shorter
use range_compare::{RangeExt, RangeCmpResult};
use std::ops::Range;
let range1 = 5..15;
let range2 = 1..15;
let result = range1.compare(&range2);
assert_eq!(
result,
RangeCmpResult::SameEndOriginalShorter {
overlapping_part: 5..15,
other_before_not_included: 1..5,
}
);
SameEndOtherShorter
The end of the range is the same as the end of the other range and the other range is shorter
use range_compare::{RangeExt, RangeCmpResult};
use std::ops::Range;
let range1 = 1..15;
let range2 = 5..15;
let result = range1.compare(&range2);
assert_eq!(
result,
RangeCmpResult::SameEndOtherShorter {
overlapping_part: 5..15,
original_before_not_included: 1..5,
}
);
Implementations§
source§impl<T> RangeCmpResult<T>
impl<T> RangeCmpResult<T>
sourcepub fn get_matching_part(&self) -> Option<&Range<T>>
pub fn get_matching_part(&self) -> Option<&Range<T>>
Get the matching part of the original range
This method returns the part of the original range which is matching the other range.
sourcepub fn get_original_not_matching_parts(&self) -> [Option<&Range<T>>; 2]
pub fn get_original_not_matching_parts(&self) -> [Option<&Range<T>>; 2]
Get the parts of the original range which are not matching the other range
Trait Implementations§
source§impl<T: Clone> Clone for RangeCmpResult<T>
impl<T: Clone> Clone for RangeCmpResult<T>
source§fn clone(&self) -> RangeCmpResult<T>
fn clone(&self) -> RangeCmpResult<T>
1.0.0 · source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read moresource§impl<T: Debug> Debug for RangeCmpResult<T>
impl<T: Debug> Debug for RangeCmpResult<T>
source§impl<T: PartialEq> PartialEq for RangeCmpResult<T>
impl<T: PartialEq> PartialEq for RangeCmpResult<T>
source§fn eq(&self, other: &RangeCmpResult<T>) -> bool
fn eq(&self, other: &RangeCmpResult<T>) -> bool
self
and other
values to be equal, and is used
by ==
.