[−][src]Struct dia_range::Range
Methods
impl<R, U> Range<R, U> where
R: RangeType<U>,
U: Ops,
[src]
R: RangeType<U>,
U: Ops,
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 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: PartialEq, U: PartialEq> PartialEq<Range<R, U>> for Range<R, U> where
R: RangeType<U>,
U: Ops,
[src]
R: RangeType<U>,
U: Ops,
impl<R, U> AsRef<Range<R, U>> for Range<R, U> where
R: RangeType<U>,
U: Ops,
[src]
R: RangeType<U>,
U: Ops,
impl<R, U> Ord for Range<R, U> where
R: RangeType<U>,
U: Ops,
[src]
R: RangeType<U>,
U: Ops,
fn cmp(&self, other: &Self) -> Ordering
[src]
fn max(self, other: Self) -> Self
1.21.0[src]
Compares and returns the maximum of two values. Read more
fn min(self, other: Self) -> Self
1.21.0[src]
Compares and returns the minimum of two values. Read more
impl<R: Eq, U: Eq> Eq for Range<R, U> where
R: RangeType<U>,
U: Ops,
[src]
R: RangeType<U>,
U: Ops,
impl<R, U> PartialOrd<Range<R, U>> for Range<R, U> where
R: RangeType<U>,
U: Ops,
[src]
R: RangeType<U>,
U: Ops,
fn partial_cmp(&self, other: &Self) -> Option<Ordering>
[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> Hash for Range<R, U> where
R: RangeType<U>,
U: Ops,
[src]
R: RangeType<U>,
U: Ops,
fn hash<H: Hasher>(&self, h: &mut H)
[src]
fn hash_slice<H>(data: &[Self], state: &mut H) where
H: Hasher,
1.3.0[src]
H: Hasher,
Feeds a slice of this type into the given [Hasher
]. Read more
impl<R: Debug, U: Debug> Debug for Range<R, U> where
R: RangeType<U>,
U: Ops,
[src]
R: RangeType<U>,
U: Ops,
Auto Trait Implementations
impl<R, U> Send for Range<R, U> where
R: Send,
U: Send,
R: Send,
U: Send,
impl<R, U> Sync for Range<R, U> where
R: Sync,
U: Sync,
R: Sync,
U: Sync,
Blanket Implementations
impl<T> From for T
[src]
impl<T, U> Into for T where
U: From<T>,
[src]
U: From<T>,
impl<T, U> TryFrom for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = !
try_from
)The type returned in the event of a conversion error.
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T> Borrow for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> BorrowMut for T where
T: ?Sized,
[src]
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T
[src]
impl<T, U> TryInto for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,