Struct BoardRange

Source
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>

Source

pub fn new() -> Self
where 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) -> bool
where 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 duplicate of the value. Read more
1.0.0 · Source§

const 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) -> Self
where 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) -> Self
where 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 for BoardRange<T>

Source§

fn eq(&self, other: &BoardRange<T>) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

const fn ne(&self, other: &Rhs) -> bool

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> StructuralPartialEq for BoardRange<T>

Auto Trait Implementations§

§

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

§

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 T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

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

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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 T
where 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 T
where T: Clone,

Source§

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 T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

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

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

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 T
where U: TryFrom<T>,

Source§

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.