Struct Position

Source
pub struct Position<T>(pub T, pub T);
Expand description

A position of a cell.

Position<T> is a tuple (T, T). The first field is the x-coordinate value of the position and the second field is the y-coordinate value of the potition. The type parameter T is used as the type of the x- and y-coordinate values of positions.

§Examples

use life_backend::Position;
let pos = Position(2, 3);
let pos_x = pos.0;
let pos_y = pos.1;
assert_eq!(pos_x, 2);
assert_eq!(pos_y, 3);

Tuple Fields§

§0: T§1: T

Implementations§

Source§

impl<T> Position<T>

Source

pub fn try_from<U>(value: Position<U>) -> Result<Position<T>, T::Error>
where T: TryFrom<U>,

Attempts to convert from Position<U> to Position<T>.

This operation converts the type of the x- and y-coordinate values of the position from U to T. If an error occurs in converting from U to T, returns that error.

§Examples
use life_backend::Position;
let base: Position<usize> = Position(0, 0);
let pos = Position::<i16>::try_from(base)?;
Source

pub fn try_into<U>(self) -> Result<Position<U>, U::Error>
where U: TryFrom<T>,

Attempts to convert from Position<T> to Position<U>.

base.try_into::<U>() is the same as Position::<U>::try_from(base), see try_from().

§Examples
use life_backend::Position;
let base: Position<usize> = Position(0, 0);
let pos: Position<i16> = base.try_into()?;
Source

pub fn moore_neighborhood_positions(&self) -> impl Iterator<Item = Self>
where T: Copy + PartialOrd + Add<Output = T> + Sub<Output = T> + One + Bounded + ToPrimitive,

Creates an owning iterator over neighbour positions of the self position in arbitrary order. The neighbour positions are defined in Moore neighbourhood.

§Examples
use std::collections::HashSet;
use life_backend::Position;
let pos = Position(2, 3);
let result: HashSet<_> = pos
    .moore_neighborhood_positions()
    .collect();
let expected: HashSet<_> = [(1, 2), (2, 2), (3, 2), (1, 3), (3, 3), (1, 4), (2, 4), (3, 4)]
    .iter()
    .copied()
    .map(|(x, y)| Position(x, y))
    .collect();
assert_eq!(result, expected);

Trait Implementations§

Source§

impl<T: Clone> Clone for Position<T>

Source§

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

Source§

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

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

impl<T> Display for Position<T>
where T: 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 Board<T>
where T: Eq + Hash + Copy + 'a,

Source§

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

Extends the board 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 live cell position.

§Examples
use life_backend::{Board, Position};
let mut board = Board::<i16>::new();
let pattern = [Position(1, 0), Position(0, 1)];
board.extend(pattern.iter());
assert_eq!(board.contains(&Position(0, 0)), false);
assert_eq!(board.contains(&Position(1, 0)), true);
assert_eq!(board.contains(&Position(0, 1)), true);
assert_eq!(board.contains(&Position(1, 1)), false);
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> 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<'a, Name, Comment> Extend<&'a Position<usize>> for PlaintextBuilder<Name, Comment>
where Name: PlaintextBuilderName, Comment: PlaintextBuilderComment,

Source§

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

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

§Examples
use life_backend::format::PlaintextBuilder;
use life_backend::Position;
let pattern = [Position(1, 0), Position(0, 1)];
let iter = pattern.iter();
let mut builder = PlaintextBuilder::new();
builder.extend(iter);
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, Name, Created, Comment, RuleSpec> Extend<&'a Position<usize>> for RleBuilder<Name, Created, Comment, RuleSpec>
where Name: RleBuilderName, Created: RleBuilderCreated, Comment: RleBuilderComment, RuleSpec: RleBuilderRule,

Source§

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

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

§Examples
use life_backend::format::RleBuilder;
use life_backend::Position;
let pattern = [Position(1, 0), Position(0, 1)];
let iter = pattern.iter();
let mut builder = RleBuilder::new();
builder.extend(iter);
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 Board<T>
where T: Eq + Hash,

Source§

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

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

§Examples
use life_backend::{Board, Position};
let mut board = Board::<i16>::new();
let pattern = [Position(1, 0), Position(0, 1)];
board.extend(pattern.into_iter());
assert_eq!(board.contains(&Position(0, 0)), false);
assert_eq!(board.contains(&Position(1, 0)), true);
assert_eq!(board.contains(&Position(0, 1)), true);
assert_eq!(board.contains(&Position(1, 1)), false);
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<Name, Comment> Extend<Position<usize>> for PlaintextBuilder<Name, Comment>
where Name: PlaintextBuilderName, Comment: PlaintextBuilderComment,

Source§

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

Extends the builder with the contents of the specified owning iterator over the series of Position<usize>. Each item in the series represents a moved live cell position.

§Examples
use life_backend::format::PlaintextBuilder;
use life_backend::Position;
let pattern = [Position(1, 0), Position(0, 1)];
let iter = pattern.into_iter();
let mut builder = PlaintextBuilder::new();
builder.extend(iter);
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<Name, Created, Comment, RuleSpec> Extend<Position<usize>> for RleBuilder<Name, Created, Comment, RuleSpec>
where Name: RleBuilderName, Created: RleBuilderCreated, Comment: RleBuilderComment, RuleSpec: RleBuilderRule,

Source§

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

Extends the builder with the contents of the specified owning iterator over the series of Position<usize>. Each item in the series represents a moved live cell position.

§Examples
use life_backend::format::RleBuilder;
use life_backend::Position;
let pattern = [Position(1, 0), Position(0, 1)];
let iter = pattern.into_iter();
let mut builder = RleBuilder::new();
builder.extend(iter);
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 Board<T>
where T: Eq + Hash + Copy + '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 live cell position.

§Examples
use life_backend::{Board, Position};
let pattern = [Position(1, 0), Position(0, 1)];
let board: Board<i16> = pattern.iter().collect();
assert_eq!(board.contains(&Position(0, 0)), false);
assert_eq!(board.contains(&Position(1, 0)), true);
assert_eq!(board.contains(&Position(0, 1)), true);
assert_eq!(board.contains(&Position(1, 1)), false);
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<'a> FromIterator<&'a Position<usize>> for PlaintextBuilder<PlaintextBuilderNoName, PlaintextBuilderNoComment>

Source§

fn from_iter<T>(iter: T) -> Self
where T: IntoIterator<Item = &'a Position<usize>>,

Creates a value from a non-owning iterator over a series of &Position<usize>. Each item in the series represents an immutable reference of a live cell position.

§Examples
use life_backend::format::PlaintextBuilder;
use life_backend::Position;
let pattern = [Position(1, 0), Position(0, 1)];
let iter = pattern.iter();
let builder: PlaintextBuilder = iter.collect();
Source§

impl<'a> FromIterator<&'a Position<usize>> for RleBuilder<RleBuilderNoName, RleBuilderNoCreated, RleBuilderNoComment, RleBuilderNoRule>

Source§

fn from_iter<T>(iter: T) -> Self
where T: IntoIterator<Item = &'a Position<usize>>,

Creates a value from a non-owning iterator over a series of &Position<usize>. Each item in the series represents an immutable reference of a live cell position.

§Examples
use life_backend::format::RleBuilder;
use life_backend::Position;
let pattern = [Position(1, 0), Position(0, 1)];
let iter = pattern.iter();
let builder: RleBuilder = iter.collect();
Source§

impl<T> FromIterator<Position<T>> for Board<T>
where T: Eq + Hash,

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 live cell position.

§Examples
use life_backend::{Board, Position};
let mut pattern = [Position(1, 0), Position(0, 1)];
let board: Board<i16> = pattern.into_iter().collect();
assert_eq!(board.contains(&Position(0, 0)), false);
assert_eq!(board.contains(&Position(1, 0)), true);
assert_eq!(board.contains(&Position(0, 1)), true);
assert_eq!(board.contains(&Position(1, 1)), false);
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 FromIterator<Position<usize>> for PlaintextBuilder<PlaintextBuilderNoName, PlaintextBuilderNoComment>

Source§

fn from_iter<T>(iter: T) -> Self
where T: IntoIterator<Item = Position<usize>>,

Creates a value from an owning iterator over a series of Position<usize>. Each item in the series represents a moved live cell position.

§Examples
use life_backend::format::PlaintextBuilder;
use life_backend::Position;
let pattern = [Position(1, 0), Position(0, 1)];
let iter = pattern.into_iter();
let builder: PlaintextBuilder = iter.collect();
Source§

impl FromIterator<Position<usize>> for RleBuilder<RleBuilderNoName, RleBuilderNoCreated, RleBuilderNoComment, RleBuilderNoRule>

Source§

fn from_iter<T>(iter: T) -> Self
where T: IntoIterator<Item = Position<usize>>,

Creates a value from an owning iterator over a series of Position<usize>. Each item in the series represents a moved live cell position.

§Examples
use life_backend::format::RleBuilder;
use life_backend::Position;
let pattern = [Position(1, 0), Position(0, 1)];
let iter = pattern.into_iter();
let builder: RleBuilder = iter.collect();
Source§

impl<T: Hash> Hash for Position<T>

Source§

fn hash<__H: Hasher>(&self, state: &mut __H)

Feeds this value into the given Hasher. Read more
1.3.0 · Source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
Source§

impl<T: PartialEq> PartialEq for Position<T>

Source§

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

Source§

impl<T: Eq> Eq for Position<T>

Source§

impl<T> StructuralPartialEq for Position<T>

Auto Trait Implementations§

§

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

§

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

§

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

§

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

§

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

§

impl<T> UnwindSafe for Position<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.