[][src]Struct dia_range::Range

pub struct Range<R, U> where
    R: RangeType<U>,
    U: Ops
{ /* fields omitted */ }

Range

Note that by default, Range is inclusive at both sides.

Methods

impl<R, U> Range<R, U> where
    R: RangeType<U>,
    U: Ops
[src]

pub fn new(start: R, end: R) -> Self[src]

Makes new instance

Start can be smaller than end, equal to end, or larger than end. They will be handled properly.

pub fn from(start: R) -> Self[src]

pub fn start(&self) -> R[src]

pub fn end(&self) -> R[src]

pub fn contains(&self, v: &R) -> bool[src]

Checks to see if this range contains given value

The check is inclusive where start <= v and v <= end.

pub fn is_full(&self) -> bool[src]

Checks to see if this range is full

A full range contains all values of its type.

Examples

use dia_range::Range;

assert!(Range::new(i64::min_value(), i64::max_value()).is_full());
assert!(Range::from(0).is_full() == false);

pub fn expand(&mut self, v: R) -> bool[src]

Expands self by 1

Examples

use dia_range::Range;

let mut range: Range<i8, u8> = Range::new(-6, 9);
assert!(range.expand(-7));
assert!(range.expand(-9) == false);
assert!(range.expand(0) == false);
assert!(range.contains(&-7));

pub fn expand_more(&mut self, v: R) -> bool[src]

Expands self

Examples

use dia_range::Range;

let mut range = Range::new(-1, 1);
assert!(range.expand_more(9));
assert_eq!(&range, &Range::new(-1, 9));
assert!(range.expand_more(-9));
assert_eq!(&range, &Range::new(-9, 9));
assert!(range.expand_more(0) == false);

pub fn shrink_start(&mut self, v: R) -> bool[src]

Shrinks start by 1

Examples

use dia_range::Range;

let mut range = Range::new(8, 9);
assert!(range.shrink_start(8) == false);
assert!(range.shrink_start(9));
assert!(range.shrink_start(10) == false);
assert_eq!(range, Range::from(9));

pub fn shrink_start_more(&mut self, v: R) -> bool[src]

Shrinks start

Examples

use dia_range::Range;

let mut range = Range::new(9, 99);
assert!(range.shrink_start_more(9) == false);
assert!(range.shrink_start_more(90));
assert!(range.shrink_start_more(1_000) == false);
assert_eq!(range, Range::new(90, 99));

pub fn shrink_end(&mut self, v: R) -> bool[src]

Shrinks end by 1

Examples

use dia_range::Range;

let mut range = Range::new(-5, 5);
assert!(range.shrink_end(5) == false);
assert!(range.shrink_end(6) == false);
assert!(range.shrink_end(3) == false);
assert!(range.shrink_end(4));
assert!(range.shrink_end(-10) == false);
assert_eq!(range, Range::new(-5, 4));

pub fn shrink_end_more(&mut self, v: R) -> bool[src]

Shrinks end

Examples

use dia_range::Range;

let mut range = Range::new(-10, 10);
assert!(range.shrink_end_more(20) == false);
assert!(range.shrink_end_more(6));
assert!(range.shrink_end_more(-30) == false);
assert_eq!(range, Range::new(-10, 6));

pub fn merge(&self, other: &Self) -> Option<Self>[src]

Merges with other range

Examples

use dia_range::Range;

assert_eq!(Range::new(0_u64, 6).merge(&Range::new(5, 9)), Some(Range::new(0, 9)));
assert_eq!(Range::new(-1_i8, 6).merge(&Range::new(8, 9)), None);

pub fn estimate_size(&self) -> U[src]

Estimates size of this range

Examples

use dia_range::Range;

assert_eq!(Range::new(0_u8, 1).estimate_size(), 2);
assert_eq!(Range::new(-1_i16, 1).estimate_size(), 3_u16);
assert_eq!(Range::new(-3_i32, -1).estimate_size(), 3_u32);
assert_eq!(Range::new(i8::min_value(), i8::max_value()).estimate_size(), u8::max_value());

Important traits for RangeIter<R>
pub fn iter(&self) -> RangeIter<R>[src]

Makes new iterator

Examples

use dia_range::Range;

assert_eq!(Range::new(-1, 1).iter().sum::<i8>(), 0);
assert_eq!(Range::from(u16::max_value()).iter().sum::<u16>(), u16::max_value());

let n = i16::from(i8::max_value());
assert_eq!(Range::new(n - 1, n).iter().sum::<i16>(), n * 2 - 1);

Trait Implementations

impl<R: Eq, U: Eq> Eq for Range<R, U> where
    R: RangeType<U>,
    U: Ops
[src]

impl<R, U> Ord for Range<R, U> where
    R: RangeType<U>,
    U: Ops
[src]

fn max(self, other: Self) -> Self1.21.0[src]

Compares and returns the maximum of two values. Read more

fn min(self, other: Self) -> Self1.21.0[src]

Compares and returns the minimum of two values. Read more

fn clamp(self, min: Self, max: Self) -> Self[src]

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

Restrict a value to a certain interval. Read more

impl<R: PartialEq, U: PartialEq> PartialEq<Range<R, U>> for Range<R, U> where
    R: RangeType<U>,
    U: Ops
[src]

impl<R: Clone, U: Clone> Clone for Range<R, U> where
    R: RangeType<U>,
    U: Ops
[src]

fn clone_from(&mut self, source: &Self)1.0.0[src]

Performs copy-assignment from source. Read more

impl<R, U> PartialOrd<Range<R, U>> for Range<R, U> where
    R: RangeType<U>,
    U: Ops
[src]

#[must_use]
fn lt(&self, other: &Rhs) -> bool
1.0.0[src]

This method tests less than (for self and other) and is used by the < operator. Read more

#[must_use]
fn le(&self, other: &Rhs) -> bool
1.0.0[src]

This method tests less than or equal to (for self and other) and is used by the <= operator. Read more

#[must_use]
fn gt(&self, other: &Rhs) -> bool
1.0.0[src]

This method tests greater than (for self and other) and is used by the > operator. Read more

#[must_use]
fn ge(&self, other: &Rhs) -> bool
1.0.0[src]

This method tests greater than or equal to (for self and other) and is used by the >= operator. Read more

impl<R, U> AsRef<Range<R, U>> for Range<R, U> where
    R: RangeType<U>,
    U: Ops
[src]

impl<R: Debug, U: Debug> Debug for Range<R, U> where
    R: RangeType<U>,
    U: Ops
[src]

impl<R, U> Hash for Range<R, U> where
    R: RangeType<U>,
    U: Ops
[src]

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

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

impl<R, U> FromStr for Range<R, U> where
    R: RangeType<U>,
    U: Ops
[src]

Parsing Range from strings

Syntax

This example is not tested
[start]..[end]
  • start must be smaller than or equal to end.
  • If start is absent, minimum value will be used.
  • If end is absent, maximum value will be used.
  • Note: the syntax is similar to Rust's ranges, however the meaning is completely different. By default, Range is inclusive at both sides. So this implementation treats input values exactly the same.
  • Some white spaces are allowed among start, .. and end.

type Err = Error

The associated error which can be returned from parsing.

Auto Trait Implementations

impl<R, U> Send for Range<R, U> where
    R: Send,
    U: Send

impl<R, U> Sync for Range<R, U> where
    R: Sync,
    U: Sync

Blanket Implementations

impl<T> ToOwned for T where
    T: Clone
[src]

type Owned = T

The resulting type after obtaining ownership.

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T> From<T> for T[src]

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

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

The type returned in the event of a conversion error.

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> Any for T where
    T: 'static + ?Sized
[src]