Struct Interval

Source
pub struct Interval<T: Debug + Display + Clone + Hash + Eq + Ord + PartialEq + PartialOrd> { /* private fields */ }

Implementations§

Source§

impl<T: Debug + Display + Clone + Hash + Eq + Ord + PartialEq + PartialOrd> Interval<T>

Source

pub fn new(lower: IntervalLimit<T>, upper: IntervalLimit<T>) -> Interval<T>

Generate an interval.

  • params
    • lower: lower interval limit
    • upper: upper interval limit
  • return: an interval
Source

pub fn over( lower: LimitValue<T>, lower_included: bool, upper: LimitValue<T>, upper_included: bool, ) -> Self

Generate an interval.

Mainly used to generate half-open interval (intervals where only one of the upper and lower limits is open).

  • params
    • lower: lower limit, Limitless means there is no limit.
    • lower_included: specify true if the lower limit is included in the interval (closed lower limit).
    • upper: upper limit, Limitless means there is no limit.
    • upper_included: specify true if the upper limit is included in the interval (closed upper limit)
  • return: an interval
  • panic
    • if the lower limit is greater than the upper limit
Source

pub fn and_more(lower: LimitValue<T>) -> Self

Generate an interval with only the lower limit.

The lower limit is the interval that is included (closed) in the interval.

  • params
    • lower: lower limit, Limitless means that there is no limit.
  • return: an interval
Source

pub fn closed(lower: LimitValue<T>, upper: LimitValue<T>) -> Self

Generate a closed interval.

  • params
    • lower: lower limit, Limitless means there is no limit.
    • upper: upper limit, Limitless means there is no limit.
  • return: a closed interval
  • panic
    • if the lower limit is greater than the upper limit
Source

pub fn more_than(lower: LimitValue<T>) -> Self

Generate an interval with only the lower limit.

The lower limit is the interval that is not included in the (open) interval.

  • params
    • lower: lower limit, Limitless means there is no limit.
  • return: an interval
Source

pub fn open(lower: LimitValue<T>, upper: LimitValue<T>) -> Self

Generate an open interval.

  • params
    • lower: lower limit, Limitless means there is no limit.
    • upper: upper limit, Limitless means there is no limit.
  • return: an open interval
Source

pub fn single_element(element: LimitValue<T>) -> Self

Generate a single-element interval.

  • params
    • element: an limit value
  • return: an interval
Source

pub fn under(upper: LimitValue<T>) -> Self

Generate an interval with only an upper limit.

The upper limit is the interval that is not included in the (open) interval.

  • params
    • upper: upper limit, Limitless means there is no limit.
  • return: an interval
Source

pub fn up_to(upper: LimitValue<T>) -> Self

Generate an interval with only an upper limit.

The upper limit is the (closed) interval included in the interval.

  • params
    • upper: upper limit, Limitless means there is no limit.
  • return: an interval
Source

pub fn as_upper_limit(&self) -> &LimitValue<T>

Source

pub fn as_lower_limit(&self) -> &LimitValue<T>

Source

pub fn covers(&self, other: &Interval<T>) -> bool

Verify that this interval completely encloses the specified interval other.

  • params
    • other: an Interval
  • return: true for full comprehension, false otherwise
Source

pub fn gap(&self, other: &Interval<T>) -> Interval<T>

Get the interval that lies between this interval and the given interval other.

For example, the gap between [3, 5) and [10, 20) is [5, 19). If the two intervals have a common part, return an empty interval.

  • params
    • other: an interval to be compared
  • return: gap interval
Source

pub fn is_single_element(&self) -> bool

Verify whether this interval is a single-element interval or not.

A single-element interval has both upper and lower limits, and also indicates that these limits are equal and not an open interval. For example, 3 <= x < 3, 3 <= x <= 3, and 3 <= x <= 3.

  • return: true if it’s a single element interval, false otherwise
Source

pub fn empty_of_same_type(&self) -> Interval<T>

Generate a new open interval with the same limits as this interval.

  • return: a new interval
Source

pub fn new_of_same_type( &self, lower: LimitValue<T>, lower_closed: bool, upper: LimitValue<T>, upper_closed: bool, ) -> Interval<T>

Generate a new interval with the same type as this interval.

  • params
    • lower: lower limit, if there is no limit value, then Limitless.
    • lower_closed: Specify true if the lower limit is included in the interval (closed lower limit).
    • upper: upper limit, if there is no limit value, then Limitless.
    • upper_closed: specify true if the upper limit is included in the interval (closed upper limit)
  • return: an new interval
Source

pub fn includes(&self, value: &LimitValue<T>) -> bool

Verify whether or not the specified value value is included in this interval.

  • params
    • value: an interval value
  • return: true if included, false otherwise
Source

pub fn is_below(&self, value: &LimitValue<T>) -> bool

Verify that the specified value value does not exceed the upper limit of this interval.

  • params
    • value: an interval value
  • return: true if not exceeded, false otherwise
Source

pub fn is_above(&self, value: &LimitValue<T>) -> bool

Verify that the specified value value does not exceed the lower limit of this interval.

  • params
    • value: an interval value
  • return: true if not exceeded, false otherwise
Source

pub fn is_open(&self) -> bool

Verify whether this interval is an open interval or not.

  • return: true if it’s an open interval, false otherwise (including half-open interval)
Source

pub fn is_closed(&self) -> bool

Verify whether this interval is a closed interval or not.

  • return: true if it’s a closed interval, false otherwise (including half-open interval)
Source

pub fn is_empty(&self) -> bool

Verify whether this interval is empty or not.

The interval is empty means that the upper and lower limits are the same value and the interval is open. For example, a state like 3 < x < 3.

  • return: true if it’s empty, false otherwise.
Source

pub fn intersect(&self, other: &Interval<T>) -> Interval<T>

Return the product set (common part) of this interval and the given interval other.

If the common part does not exist, it returns an empty interval.

  • params
    • other: an interval to be compared
Source

pub fn intersects(&self, other: &Interval<T>) -> bool

Verify if there is a common part between this interval and the given interval other.

  • params
    • other: a target interval
  • return: true if the common part exists, false otherwise
Source

pub fn has_upper_limit(&self) -> bool

Get whether there is an upper limit or not.

Warning: This method is generally used for the purpose of displaying this value and for interaction with classes that are highly coupled to this class. Careless use of this method will unnecessarily increase the coupling between this class and the client-side class.

If you want to use this value for calculations,

  • find another appropriate method or add a new method to this class.

  • find another suitable method or consider adding a new method to this class.

  • return: true if upper limit is present, false otherwise

Source

pub fn has_lower_limit(&self) -> bool

Get whether there is an lower limit or not.

Warning: This method is generally used for the purpose of displaying this value and for interaction with classes that are highly coupled to this class. Careless use of this method will unnecessarily increase the coupling between this class and the client-side class.

If you want to use this value for calculations,

  • find another appropriate method or add a new method to this class.

  • find another suitable method or consider adding a new method to this class.

  • return: true if lower limit is present, false otherwise

Source

pub fn includes_upper_limit(&self) -> bool

Get whether the upper limit is closed or not.

Warning: This method is generally used for the purpose of displaying this value and for interaction with classes that are highly coupled to this class. Careless use of this method will unnecessarily increase the coupling between this class and the client-side class.

If you want to use this value for calculations,

  • find another appropriate method or add a new method to this class.

  • find another suitable method or consider adding a new method to this class.

  • return: trueif the upper limit is closed,false` otherwise

Source

pub fn includes_lower_limit(&self) -> bool

Get whether the lower limit is closed or not.

Warning: This method is generally used for the purpose of displaying this value and for interaction with classes that are highly coupled to this class. Careless use of this method will unnecessarily increase the coupling between this class and the client-side class.

If you want to use this value for calculations,

  • find another appropriate method or add a new method to this class.

  • find another suitable method or consider adding a new method to this class.

  • return: trueif the lower limit is closed,false` otherwise

Trait Implementations§

Source§

impl<T: Clone + Debug + Display + Clone + Hash + Eq + Ord + PartialEq + PartialOrd> Clone for Interval<T>

Source§

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

Returns a duplicate 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 + Display + Clone + Hash + Eq + Ord + PartialEq + PartialOrd> Debug for Interval<T>

Source§

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

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

impl<T: Debug + Display + Clone + Hash + Eq + Ord + PartialEq + PartialOrd> Display for Interval<T>

Source§

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

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

impl<T: Hash + Debug + Display + Clone + Hash + Eq + Ord + PartialEq + PartialOrd> Hash for Interval<T>

Source§

fn hash<__H: Hasher>(&self, state: &mut __H)

Feeds this value into the given Hasher. Read more
1.3.0 · Source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

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

impl<T: Debug + Display + Clone + Hash + Eq + Ord + PartialEq + PartialOrd> PartialEq for Interval<T>

Source§

fn eq(&self, other: &Self) -> bool

Verify the identity of this interval and the given interval other.

It returns true if both intervals are empty, and false if only one of them is empty. If both are single-element intervals, the limits that are single elements are compared with each other, and true is returned if they match. If only one of them is a single-element interval, false is returned.

  • param
    • other: an interval to be compared
  • return: true if they are identical, false if they are not
1.0.0 · Source§

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

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl<T: Eq + Debug + Display + Clone + Hash + Eq + Ord + PartialEq + PartialOrd> Eq for Interval<T>

Auto Trait Implementations§

§

impl<T> Freeze for Interval<T>
where T: Freeze,

§

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

§

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

§

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

§

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

§

impl<T> UnwindSafe for Interval<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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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,

Source§

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> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. Read more
Source§

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

Source§

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

Source§

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.