pub struct BoardRange<T>(/* private fields */);
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>
impl<T> BoardRange<T>
Sourcepub fn new() -> Self
pub fn new() -> Self
Creates an empty range.
§Examples
use life_backend::BoardRange;
let range = BoardRange::<i32>::new();
assert!(range.is_empty());
Sourcepub const fn x(&self) -> &RangeInclusive<T>
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));
Sourcepub const fn y(&self) -> &RangeInclusive<T>
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));
Sourcepub fn into_inner(self) -> (RangeInclusive<T>, RangeInclusive<T>)
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);
Sourcepub fn is_empty(&self) -> boolwhere
T: PartialOrd,
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()
istrue
range.x().is_empty()
andrange.y().is_empty()
aretrue
range.x().start()
,range.x().end()
,range.y().start()
andrange.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>
impl<T: Clone> Clone for BoardRange<T>
Source§fn clone(&self) -> BoardRange<T>
fn clone(&self) -> BoardRange<T>
1.0.0 · Source§const fn clone_from(&mut self, source: &Self)
const fn clone_from(&mut self, source: &Self)
source
. Read moreSource§impl<T: Debug> Debug for BoardRange<T>
impl<T: Debug> Debug for BoardRange<T>
Source§impl<T> Default for BoardRange<T>
impl<T> Default for BoardRange<T>
Source§impl<T> Display for BoardRange<T>where
T: PartialOrd + Display,
impl<T> Display for BoardRange<T>where
T: PartialOrd + Display,
Source§impl<'a, T> Extend<&'a Position<T>> for BoardRange<T>
impl<'a, T> Extend<&'a Position<T>> for BoardRange<T>
Source§fn extend<U>(&mut self, iter: U)where
U: IntoIterator<Item = &'a Position<T>>,
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)
fn extend_one(&mut self, item: A)
extend_one
)Source§fn extend_reserve(&mut self, additional: usize)
fn extend_reserve(&mut self, additional: usize)
extend_one
)Source§impl<T> Extend<Position<T>> for BoardRange<T>
impl<T> Extend<Position<T>> for BoardRange<T>
Source§fn extend<U>(&mut self, iter: U)where
U: IntoIterator<Item = Position<T>>,
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)
fn extend_one(&mut self, item: A)
extend_one
)Source§fn extend_reserve(&mut self, additional: usize)
fn extend_reserve(&mut self, additional: usize)
extend_one
)Source§impl<'a, T> FromIterator<&'a Position<T>> for BoardRange<T>
impl<'a, T> FromIterator<&'a Position<T>> for BoardRange<T>
Source§fn from_iter<U>(iter: U) -> Selfwhere
U: IntoIterator<Item = &'a Position<T>>,
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>
impl<T> FromIterator<Position<T>> for BoardRange<T>
Source§fn from_iter<U>(iter: U) -> Selfwhere
U: IntoIterator<Item = Position<T>>,
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));