pub struct BoardRange<T>(_, _);
Expand description

A range on a board.

This range consists of four pieces of information: the minimum and maximum x-coordinate values and the minimum and maximum y-coordinate values. The type parameter T is used as the type of the x- and y-coordinate values.

Examples

use life_backend::{BoardRange, Position};
let positions = [Position(0, 0), Position(1, 0), Position(2, 0), Position(1, 1)];
let range: BoardRange<_> = positions.iter().collect();
let min_x = range.x().start();
let max_x = range.x().end();
let min_y = range.y().start();
let max_y = range.y().end();
assert_eq!(min_x, &0);
assert_eq!(max_x, &2);
assert_eq!(min_y, &0);
assert_eq!(max_y, &1);

Implementations§

source§

impl<T> BoardRange<T>

source

pub fn new() -> Selfwhere T: Zero + One,

Creates an empty range.

Examples
use life_backend::BoardRange;
let range = BoardRange::<i32>::new();
assert!(range.is_empty());
source

pub const fn x(&self) -> &RangeInclusive<T>

Returns the range on the x-coordinate.

Examples
use life_backend::{BoardRange, Position};
let positions = [Position(0, 0), Position(1, 0), Position(2, 0), Position(1, 1)];
let range: BoardRange<_> = positions.iter().collect();
assert_eq!(range.x(), &(0..=2));
source

pub const fn y(&self) -> &RangeInclusive<T>

Returns the range on the y-coordinate.

Examples
use life_backend::{BoardRange, Position};
let positions = [Position(0, 0), Position(1, 0), Position(2, 0), Position(1, 1)];
let range: BoardRange<_> = positions.iter().collect();
assert_eq!(range.y(), &(0..=1));
source

pub fn into_inner(self) -> (RangeInclusive<T>, RangeInclusive<T>)

Destructures BoardRange into (range-x, range-y).

Examples
use life_backend::{BoardRange, Position};
let positions = [Position(0, 0), Position(1, 0), Position(2, 0), Position(1, 1)];
let range: BoardRange<_> = positions.iter().collect();
let (range_x, range_y) = range.into_inner();
assert_eq!(range_x, 0..=2);
assert_eq!(range_y, 0..=1);
source

pub fn is_empty(&self) -> boolwhere T: PartialOrd,

Returns true if the range contains no area.

If the range is empty, return values of methods are defined as the following:

  • range.is_empty() is true
  • range.x().is_empty() and range.y().is_empty() are true
  • range.x().start(), range.x().end(), range.y().start() and range.y().end() are unspecified
Examples
use life_backend::{BoardRange, Position};
let positions = [Position(0, 0), Position(1, 0), Position(2, 0), Position(1, 1)];
let range: BoardRange<_> = positions.iter().collect();
assert!(!range.is_empty());

Trait Implementations§

source§

impl<T: Clone> Clone for BoardRange<T>

source§

fn clone(&self) -> BoardRange<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 BoardRange<T>

source§

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

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

impl<T> Default for BoardRange<T>where T: Zero + One,

source§

fn default() -> Self

Returns the default value of the type, same as the return value of new().

source§

impl<T> Display for BoardRange<T>where T: PartialOrd + Display,

source§

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

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

impl<'a, T> Extend<&'a Position<T>> for BoardRange<T>where T: Copy + PartialOrd + Zero + One + 'a,

source§

fn extend<U>(&mut self, iter: U)where U: IntoIterator<Item = &'a Position<T>>,

Extends the range with the contents of the specified non-owning iterator over the series of &Position<T>. Each item in the series represents an immutable reference of a position.

Examples
use life_backend::{BoardRange, Position};
let positions = [Position(0, 0), Position(1, 0), Position(2, 0), Position(1, 1)];
let mut range = BoardRange::new();
range.extend(positions.iter());
assert!(!range.is_empty());
assert_eq!(range.x(), &(0..=2));
assert_eq!(range.y(), &(0..=1));
source§

fn extend_one(&mut self, item: A)

🔬This is a nightly-only experimental API. (extend_one)
Extends a collection with exactly one element.
source§

fn extend_reserve(&mut self, additional: usize)

🔬This is a nightly-only experimental API. (extend_one)
Reserves capacity in a collection for the given number of additional elements. Read more
source§

impl<T> Extend<Position<T>> for BoardRange<T>where T: Copy + PartialOrd + Zero + One,

source§

fn extend<U>(&mut self, iter: U)where U: IntoIterator<Item = Position<T>>,

Extends the range with the contents of the specified owning iterator over the series of Position<T>. Each item in the series represents a moved position.

Examples
use life_backend::{BoardRange, Position};
let positions = [Position(0, 0), Position(1, 0), Position(2, 0), Position(1, 1)];
let mut range = BoardRange::new();
range.extend(positions.into_iter());
assert!(!range.is_empty());
assert_eq!(range.x(), &(0..=2));
assert_eq!(range.y(), &(0..=1));
source§

fn extend_one(&mut self, item: A)

🔬This is a nightly-only experimental API. (extend_one)
Extends a collection with exactly one element.
source§

fn extend_reserve(&mut self, additional: usize)

🔬This is a nightly-only experimental API. (extend_one)
Reserves capacity in a collection for the given number of additional elements. Read more
source§

impl<'a, T> FromIterator<&'a Position<T>> for BoardRange<T>where T: Copy + PartialOrd + Zero + One + 'a,

source§

fn from_iter<U>(iter: U) -> Selfwhere U: IntoIterator<Item = &'a Position<T>>,

Creates a value from a non-owning iterator over a series of &Position<T>. Each item in the series represents an immutable reference of a position to be contained to the range.

Examples
use life_backend::{BoardRange, Position};
let positions = [Position(0, 0), Position(1, 0), Position(2, 0), Position(1, 1)];
let range: BoardRange<_> = positions.iter().collect();
assert!(!range.is_empty());
assert_eq!(range.x(), &(0..=2));
assert_eq!(range.y(), &(0..=1));
source§

impl<T> FromIterator<Position<T>> for BoardRange<T>where T: Copy + PartialOrd + Zero + One,

source§

fn from_iter<U>(iter: U) -> Selfwhere U: IntoIterator<Item = Position<T>>,

Creates a value from an owning iterator over a series of Position<T>. Each item in the series represents a moved position to be contained to the range.

Examples
use life_backend::{BoardRange, Position};
let positions = [Position(0, 0), Position(1, 0), Position(2, 0), Position(1, 1)];
let range: BoardRange<_> = positions.into_iter().collect();
assert!(!range.is_empty());
assert_eq!(range.x(), &(0..=2));
assert_eq!(range.y(), &(0..=1));
source§

impl<T: PartialEq> PartialEq<BoardRange<T>> for BoardRange<T>

source§

fn eq(&self, other: &BoardRange<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 BoardRange<T>

source§

impl<T> StructuralEq for BoardRange<T>

source§

impl<T> StructuralPartialEq for BoardRange<T>

Auto Trait Implementations§

§

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

§

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

§

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

§

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

§

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

Blanket Implementations§

source§

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

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

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

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

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

source§

default fn to_string(&self) -> String

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

impl<T, U> TryFrom<U> for Twhere 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 Twhere 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.