pub trait PosT:
Debug
+ Default
+ Eq
+ PartialOrd
+ Copy {
type Xtype: BoundedInt;
type Ytype: BoundedInt;
const WIDTH: usize;
const HEIGHT: usize;
Show 37 methods
// Required method
fn new_(xy: (Self::Xtype, Self::Ytype)) -> Self;
// Provided methods
fn new<X, Y>(x: X, y: Y) -> Result<Self, Error>
where X: BoundedInt,
Y: BoundedInt,
Self::Xtype: TryFrom<X>,
Self::Ytype: TryFrom<Y>,
Self: Sized { ... }
fn into_tuple(self) -> (Self::Xtype, Self::Ytype)
where Self: Sized { ... }
fn tuple(&self) -> (Self::Xtype, Self::Ytype) { ... }
fn x(&self) -> Self::Xtype { ... }
fn y(&self) -> Self::Ytype { ... }
fn inner_tuple(
self,
) -> (<Self::Xtype as BoundedInt>::Inner, <Self::Ytype as BoundedInt>::Inner) { ... }
fn tryfrom_pos<P>(pos: P) -> Result<Self, Error>
where P: PosT,
Self::Xtype: TryFrom<<P::Xtype as BoundedInt>::Inner>,
Self::Ytype: TryFrom<<P::Ytype as BoundedInt>::Inner>,
<P::Xtype as BoundedInt>::Inner: BoundedInt,
<P::Ytype as BoundedInt>::Inner: BoundedInt,
Self: Sized { ... }
fn width() -> usize { ... }
fn height() -> usize { ... }
fn dimensions() -> usize { ... }
fn first() -> Self
where Self: Sized { ... }
fn last() -> Self
where Self: Sized { ... }
fn is_corner(&self) -> bool { ... }
fn is_side(&self) -> bool { ... }
fn flip_h(&self) -> Self
where Self: Sized { ... }
fn flip_v(&self) -> Self
where Self: Sized { ... }
fn manhattan(&self, pos: &Self) -> usize { ... }
fn inside(&self, pos1: &Self, pos2: &Self) -> bool { ... }
fn to_usize(&self) -> usize { ... }
fn tryfrom_usize(i: usize) -> Result<Self, Error>
where Self: Sized { ... }
fn next(&self) -> Option<Self>
where Self: Sized { ... }
fn next_y(&self) -> Option<Self>
where Self: Sized { ... }
fn prev(&self) -> Option<Self>
where Self: Sized { ... }
fn prev_y(&self) -> Option<Self>
where Self: Sized { ... }
fn iter_x() -> impl Iterator<Item = Self::Xtype> { ... }
fn iter_y() -> impl Iterator<Item = Self::Ytype> { ... }
fn iter_orientation<const XFIRST: bool>() -> PosTIter<XFIRST, Self> ⓘ
where Self: Sized { ... }
fn iter() -> PosTIter<true, Self> ⓘ
where Self: Sized { ... }
fn iter_horizontal() -> PosTIter<true, Self> ⓘ
where Self: Sized { ... }
fn iter_vertical() -> PosTIter<false, Self> ⓘ
where Self: Sized { ... }
fn iter_range(topleft: Self, botright: Self) -> PosTIterRange<Self> ⓘ
where Self: Sized + Copy { ... }
fn iter_in_x(x: Self::Xtype) -> PosTIterInX<Self> ⓘ
where Self: Sized { ... }
fn iter_in_y(y: Self::Ytype) -> PosTIterInY<Self> ⓘ
where Self: Sized { ... }
fn tlbr_of(iter: impl Iterator<Item = Self>) -> Result<(Self, Self), Error>
where Self: Sized { ... }
fn rotate_cw(&self) -> Self
where <<Self as PosT>::Ytype as BoundedInt>::Inner: Sub<Output = <<Self as PosT>::Ytype as BoundedInt>::Inner>,
Self::Xtype: TryFrom<<<Self as PosT>::Ytype as BoundedInt>::Inner>,
Self::Ytype: TryFrom<<<Self as PosT>::Xtype as BoundedInt>::Inner> { ... }
fn rotate_cc(&self) -> Self
where <<Self as PosT>::Xtype as BoundedInt>::Inner: Sub<Output = <<Self as PosT>::Xtype as BoundedInt>::Inner>,
Self::Xtype: TryFrom<<<Self as PosT>::Ytype as BoundedInt>::Inner>,
Self::Ytype: TryFrom<<<Self as PosT>::Xtype as BoundedInt>::Inner> { ... }
}Expand description
Position trait
Required Associated Constants§
Required Associated Types§
Sourcetype Xtype: BoundedInt
type Xtype: BoundedInt
The type of the X coordinate
Sourcetype Ytype: BoundedInt
type Ytype: BoundedInt
The type of the Y coordinate
Required Methods§
Provided Methods§
Sourcefn into_tuple(self) -> (Self::Xtype, Self::Ytype)where
Self: Sized,
fn into_tuple(self) -> (Self::Xtype, Self::Ytype)where
Self: Sized,
Return the corresponding tuple
Defining this can lead to less copies.
Sourcefn tuple(&self) -> (Self::Xtype, Self::Ytype)
fn tuple(&self) -> (Self::Xtype, Self::Ytype)
Return the corresponding tuple
You can either define both PosT::x and PosT::y, or
PosT::tuple.
Sourcefn x(&self) -> Self::Xtype
fn x(&self) -> Self::Xtype
Get the X component
You can either define both PosT::x and PosT::y, or
PosT::tuple.
Sourcefn y(&self) -> Self::Ytype
fn y(&self) -> Self::Ytype
Get the Y component
You can either define both PosT::x and PosT::y, or
PosT::tuple.
Sourcefn inner_tuple(
self,
) -> (<Self::Xtype as BoundedInt>::Inner, <Self::Ytype as BoundedInt>::Inner)
fn inner_tuple( self, ) -> (<Self::Xtype as BoundedInt>::Inner, <Self::Ytype as BoundedInt>::Inner)
Return the corresponding inner tuple
Sourcefn tryfrom_pos<P>(pos: P) -> Result<Self, Error>where
P: PosT,
Self::Xtype: TryFrom<<P::Xtype as BoundedInt>::Inner>,
Self::Ytype: TryFrom<<P::Ytype as BoundedInt>::Inner>,
<P::Xtype as BoundedInt>::Inner: BoundedInt,
<P::Ytype as BoundedInt>::Inner: BoundedInt,
Self: Sized,
fn tryfrom_pos<P>(pos: P) -> Result<Self, Error>where
P: PosT,
Self::Xtype: TryFrom<<P::Xtype as BoundedInt>::Inner>,
Self::Ytype: TryFrom<<P::Ytype as BoundedInt>::Inner>,
<P::Xtype as BoundedInt>::Inner: BoundedInt,
<P::Ytype as BoundedInt>::Inner: BoundedInt,
Self: Sized,
Create a position from another position
Sourcefn dimensions() -> usize
fn dimensions() -> usize
Return the total dimension supported by the position type
Sourcefn inside(&self, pos1: &Self, pos2: &Self) -> bool
fn inside(&self, pos1: &Self, pos2: &Self) -> bool
Check that the position is inside the provided limits
Sourcefn tryfrom_usize(i: usize) -> Result<Self, Error>where
Self: Sized,
fn tryfrom_usize(i: usize) -> Result<Self, Error>where
Self: Sized,
Create a new position from the provided usize, if possible;
return an error otherwise.
Sourcefn next(&self) -> Option<Self>where
Self: Sized,
fn next(&self) -> Option<Self>where
Self: Sized,
Return the next position horizontally (English read sequence), or None
if self is the last one.
Sourcefn next_y(&self) -> Option<Self>where
Self: Sized,
fn next_y(&self) -> Option<Self>where
Self: Sized,
Return the next position vertically, or None
if self is the last one.
Sourcefn prev(&self) -> Option<Self>where
Self: Sized,
fn prev(&self) -> Option<Self>where
Self: Sized,
Return the previous position horizontally (English read sequence), or None
if self is the first one.
Sourcefn prev_y(&self) -> Option<Self>where
Self: Sized,
fn prev_y(&self) -> Option<Self>where
Self: Sized,
Return the previous position vertically, or None
if self is the first one.
Sourcefn iter_orientation<const XFIRST: bool>() -> PosTIter<XFIRST, Self> ⓘwhere
Self: Sized,
fn iter_orientation<const XFIRST: bool>() -> PosTIter<XFIRST, Self> ⓘwhere
Self: Sized,
Return an iterator that returns all positions within the grid
dimensions in the given orientation - true for horizontally,
false for vertically.
Sourcefn iter() -> PosTIter<true, Self> ⓘwhere
Self: Sized,
fn iter() -> PosTIter<true, Self> ⓘwhere
Self: Sized,
Return an iterator that returns all positions within the grid dimensions.
Sourcefn iter_horizontal() -> PosTIter<true, Self> ⓘwhere
Self: Sized,
fn iter_horizontal() -> PosTIter<true, Self> ⓘwhere
Self: Sized,
Return an iterator that returns all positions within the grid dimensions horizontally.
Sourcefn iter_vertical() -> PosTIter<false, Self> ⓘwhere
Self: Sized,
fn iter_vertical() -> PosTIter<false, Self> ⓘwhere
Self: Sized,
Return an iterator that returns all positions within the grid dimensions vertically.
Sourcefn iter_range(topleft: Self, botright: Self) -> PosTIterRange<Self> ⓘ
fn iter_range(topleft: Self, botright: Self) -> PosTIterRange<Self> ⓘ
Return an iterator that returns all positions within the grid coordinates.
Sourcefn iter_in_x(x: Self::Xtype) -> PosTIterInX<Self> ⓘwhere
Self: Sized,
fn iter_in_x(x: Self::Xtype) -> PosTIterInX<Self> ⓘwhere
Self: Sized,
Return an iterator that returns all positions in a column.
Sourcefn iter_in_y(y: Self::Ytype) -> PosTIterInY<Self> ⓘwhere
Self: Sized,
fn iter_in_y(y: Self::Ytype) -> PosTIterInY<Self> ⓘwhere
Self: Sized,
Return an iterator that returns all positions in a line.
Sourcefn tlbr_of(iter: impl Iterator<Item = Self>) -> Result<(Self, Self), Error>where
Self: Sized,
fn tlbr_of(iter: impl Iterator<Item = Self>) -> Result<(Self, Self), Error>where
Self: Sized,
Calculate a top-left and a bottom-right Pos’s that contains all iterated points.
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.