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

Fields

§other_before: Range<T>
§other_after: Range<T>
§overlapping_part: Range<T>

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

§other_after: Range<T>
§original_part_which_is_not_included: Range<T>
§overlapping_part: Range<T>

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

§other_before: Range<T>
§original_part_which_is_not_included: Range<T>
§overlapping_part: Range<T>

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

§overlapping_part: Range<T>
§original_before_not_included: Range<T>
§original_after_not_included: Range<T>

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

Fields

§overlapping_part: Range<T>
§other_after_not_included: Range<T>

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

Fields

§overlapping_part: Range<T>
§original_after_not_included: Range<T>

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

Fields

§overlapping_part: Range<T>
§other_before_not_included: Range<T>

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

Fields

§overlapping_part: Range<T>
§original_before_not_included: Range<T>

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>

source

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.

source

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>

source§

fn clone(&self) -> RangeCmpResult<T>

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
source§

impl<T: Debug> Debug for RangeCmpResult<T>

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl<T: PartialEq> PartialEq for RangeCmpResult<T>

source§

fn eq(&self, other: &RangeCmpResult<T>) -> bool

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

fn ne(&self, other: &Rhs) -> bool

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl<T: Eq> Eq for RangeCmpResult<T>

source§

impl<T> StructuralEq for RangeCmpResult<T>

source§

impl<T> StructuralPartialEq for RangeCmpResult<T>

Auto Trait Implementations§

§

impl<T> RefUnwindSafe for RangeCmpResult<T>
where T: RefUnwindSafe,

§

impl<T> Send for RangeCmpResult<T>
where T: Send,

§

impl<T> Sync for RangeCmpResult<T>
where T: Sync,

§

impl<T> Unpin for RangeCmpResult<T>
where T: Unpin,

§

impl<T> UnwindSafe for RangeCmpResult<T>
where T: UnwindSafe,

Blanket Implementations§

source§

impl<T> Any for T
where T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for T
where T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for T
where U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T> ToOwned for T
where T: Clone,

§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

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

fn clone_into(&self, target: &mut T)

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

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.