[][src]Struct gridly::range::ComponentRange

pub struct ComponentRange<C: Component> { /* fields omitted */ }

A range over Row or Column values. Much like the standard rust Range, it is half open, bounded by [start..end). It supports simple accessors and iteration. It also forms the basis for bounds checking, through the check method.

Methods

impl<C: Component> ComponentRange<C>[src]

#[must_use] pub fn bounded(start: C, end: C) -> Self[src]

Create a range bounded by [start .. end).

Example:

use gridly::range::ComponentRange;
use gridly::location::Row;
use gridly::vector::Rows;

let mut range = ComponentRange::bounded(Row(0), Row(3));

assert_eq!(range.size(), Rows(3));
assert_eq!(range.start(), Row(0));
assert_eq!(range.end(), Row(3));

assert_eq!(range.next(), Some(Row(0)));
assert_eq!(range.next(), Some(Row(1)));
assert_eq!(range.next(), Some(Row(2)));
assert_eq!(range.next(), None);

#[must_use] pub fn span(start: C, size: C::Distance) -> Self[src]

Create a range starting at start with length size

Example:

use gridly::range::ComponentRange;
use gridly::location::Column;
use gridly::vector::Columns;

let mut range = ComponentRange::span(Column(1), Columns(2));

assert_eq!(range.size(), Columns(2));
assert_eq!(range.start(), Column(1));
assert_eq!(range.end(), Column(3));

assert_eq!(range.next(), Some(Column(1)));
assert_eq!(range.next(), Some(Column(2)));
assert_eq!(range.next(), None);

#[must_use] pub fn start(&self) -> C[src]

Get the start index of the range

#[must_use] pub fn end(&self) -> C[src]

Get the end index of the range

#[must_use] pub fn size(&self) -> C::Distance[src]

Get the size of the range

Example:

use gridly::range::ComponentRange;
use gridly::location::Row;
use gridly::vector::Rows;

let range = ComponentRange::bounded(Row(-1), Row(3));
assert_eq!(range.size(), Rows(4));

pub fn check(&self, idx: impl Into<C>) -> Result<C, RangeError<C>>[src]

Check that a Row or Column is in bounds for this range. If it is, return the index as a Row or Column; otherwise, return a RangeError indivating if the index was too high or too low, and what the exceeded upper or lower bound is.

Example:

use gridly::range::{ComponentRange, RangeError};
use gridly::location::Row;
use gridly::vector::Rows;

let range = ComponentRange::span(Row(3), Rows(5));
assert_eq!(range.check(Row(4)), Ok(Row(4)));
assert_eq!(range.check(Row(0)), Err(RangeError::TooLow(Row(3))));
assert_eq!(range.check(Row(8)), Err(RangeError::TooHigh(Row(8))));

// This can also be used to quickly map an `isize` to a `Row` or `Column`
assert_eq!(range.check(5), Ok(Row(5)));

#[must_use] pub fn in_bounds(&self, loc: impl Into<C>) -> bool[src]

Check that a Row or Column is in bounds for this range.

Important traits for LocationRange<C>
#[must_use] pub fn cross(self, index: C::Converse) -> LocationRange<C::Converse>[src]

Combine an index range with a converse index to create a LocationRange

Example:

use gridly::range::RowRange;
use gridly::location::{Row, Column};
use gridly::shorthand::L;

let row_range = RowRange::bounded(Row(3), Row(6));
let mut loc_range = row_range.cross(Column(4));

assert_eq!(loc_range.next(), Some(L(3, 4)));
assert_eq!(loc_range.next(), Some(L(4, 4)));
assert_eq!(loc_range.next(), Some(L(5, 4)));
assert_eq!(loc_range.next(), None);

Trait Implementations

impl<C: Clone + Component> Clone for ComponentRange<C>[src]

impl<C: Debug + Component> Debug for ComponentRange<C>[src]

impl<C: Component> DoubleEndedIterator for ComponentRange<C>[src]

impl<C: Eq + Component> Eq for ComponentRange<C>[src]

impl<C: Component> ExactSizeIterator for ComponentRange<C>[src]

impl<C: Component> FusedIterator for ComponentRange<C>[src]

impl<C: Hash + Component> Hash for ComponentRange<C>[src]

impl<C: Component> Iterator for ComponentRange<C>[src]

type Item = C

The type of the elements being iterated over.

impl<C: PartialEq + Component> PartialEq<ComponentRange<C>> for ComponentRange<C>[src]

impl<C: Component> StructuralEq for ComponentRange<C>[src]

impl<C: Component> StructuralPartialEq for ComponentRange<C>[src]

Auto Trait Implementations

impl<C> RefUnwindSafe for ComponentRange<C> where
    C: RefUnwindSafe

impl<C> Send for ComponentRange<C> where
    C: Send

impl<C> Sync for ComponentRange<C> where
    C: Sync

impl<C> Unpin for ComponentRange<C> where
    C: Unpin

impl<C> UnwindSafe for ComponentRange<C> where
    C: UnwindSafe

Blanket Implementations

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

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

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

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

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

impl<I> IntoIterator for I where
    I: Iterator
[src]

type Item = <I as Iterator>::Item

The type of the elements being iterated over.

type IntoIter = I

Which kind of iterator are we turning this into?

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

type Owned = T

The resulting type after obtaining ownership.

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

type Error = !

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.