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>
impl<T> Position<T>
Sourcepub fn try_from<U>(value: Position<U>) -> Result<Position<T>, T::Error>where
T: TryFrom<U>,
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)?;
Sourcepub fn try_into<U>(self) -> Result<Position<U>, U::Error>where
U: TryFrom<T>,
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()?;
Sourcepub fn moore_neighborhood_positions(&self) -> impl Iterator<Item = Self>
pub fn moore_neighborhood_positions(&self) -> impl Iterator<Item = Self>
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<'a, T> Extend<&'a Position<T>> for Board<T>
impl<'a, T> Extend<&'a Position<T>> for Board<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 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)
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> 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<'a, Name, Comment> Extend<&'a Position<usize>> for PlaintextBuilder<Name, Comment>where
Name: PlaintextBuilderName,
Comment: PlaintextBuilderComment,
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)
fn extend<T>(&mut self, iter: T)
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)
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, Name, Created, Comment, RuleSpec> Extend<&'a Position<usize>> for RleBuilder<Name, Created, Comment, RuleSpec>where
Name: RleBuilderName,
Created: RleBuilderCreated,
Comment: RleBuilderComment,
RuleSpec: RleBuilderRule,
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)
fn extend<T>(&mut self, iter: T)
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)
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 Board<T>
impl<T> Extend<Position<T>> for Board<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 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)
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<Name, Comment> Extend<Position<usize>> for PlaintextBuilder<Name, Comment>where
Name: PlaintextBuilderName,
Comment: PlaintextBuilderComment,
impl<Name, Comment> Extend<Position<usize>> for PlaintextBuilder<Name, Comment>where
Name: PlaintextBuilderName,
Comment: PlaintextBuilderComment,
Source§fn extend<T>(&mut self, iter: T)
fn extend<T>(&mut self, iter: T)
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)
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<Name, Created, Comment, RuleSpec> Extend<Position<usize>> for RleBuilder<Name, Created, Comment, RuleSpec>where
Name: RleBuilderName,
Created: RleBuilderCreated,
Comment: RleBuilderComment,
RuleSpec: RleBuilderRule,
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)
fn extend<T>(&mut self, iter: T)
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)
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 Board<T>
impl<'a, T> FromIterator<&'a Position<T>> for Board<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 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>
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<'a> FromIterator<&'a Position<usize>> for PlaintextBuilder<PlaintextBuilderNoName, PlaintextBuilderNoComment>
impl<'a> FromIterator<&'a Position<usize>> for PlaintextBuilder<PlaintextBuilderNoName, PlaintextBuilderNoComment>
Source§fn from_iter<T>(iter: T) -> Self
fn from_iter<T>(iter: T) -> Self
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>
impl<'a> FromIterator<&'a Position<usize>> for RleBuilder<RleBuilderNoName, RleBuilderNoCreated, RleBuilderNoComment, RleBuilderNoRule>
Source§fn from_iter<T>(iter: T) -> Self
fn from_iter<T>(iter: T) -> Self
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>
impl<T> FromIterator<Position<T>> for Board<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 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>
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));
Source§impl FromIterator<Position<usize>> for PlaintextBuilder<PlaintextBuilderNoName, PlaintextBuilderNoComment>
impl FromIterator<Position<usize>> for PlaintextBuilder<PlaintextBuilderNoName, PlaintextBuilderNoComment>
Source§fn from_iter<T>(iter: T) -> Self
fn from_iter<T>(iter: T) -> Self
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>
impl FromIterator<Position<usize>> for RleBuilder<RleBuilderNoName, RleBuilderNoCreated, RleBuilderNoComment, RleBuilderNoRule>
Source§fn from_iter<T>(iter: T) -> Self
fn from_iter<T>(iter: T) -> Self
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();