pub trait Shape: Clone {
type Axis: Axis;
type Coordinate: Coordinate;
type OffsetConvertError: Debug + Clone;
type CoordinateMoveError: Debug + Clone;
Show 16 methods
// Required methods
fn horizontal(&self) -> usize;
fn vertical(&self) -> usize;
fn to_offset(
&self,
coord: Self::Coordinate,
) -> Result<Offset, Self::OffsetConvertError>;
fn offset_to_coordinate(&self, offset: Offset) -> Self::Coordinate;
fn move_coord(
&self,
coord: Self::Coordinate,
dir: <Self::Axis as Axis>::Direction,
) -> Result<Self::Coordinate, Self::CoordinateMoveError>;
// Provided methods
fn node_count(&self) -> usize { ... }
unsafe fn to_offset_unchecked(&self, coord: Self::Coordinate) -> Offset { ... }
fn index_to_coordinate(&self, index: usize) -> Self::Coordinate { ... }
fn to_index(&self, coord: Self::Coordinate) -> Option<usize> { ... }
fn index_to_offset(&self, index: usize) -> Offset { ... }
fn offset_to_index(&self, o: Offset) -> usize { ... }
fn horizontal_edge_size(&self, _axis: Self::Axis) -> usize { ... }
fn vertical_edge_size(&self, _axis: Self::Axis) -> usize { ... }
unsafe fn move_coord_unchecked(
&self,
coord: Self::Coordinate,
dir: <Self::Axis as Axis>::Direction,
) -> Self::Coordinate { ... }
fn is_neighbor(&self, a: Self::Coordinate, b: Self::Coordinate) -> bool { ... }
fn get_direction(
&self,
source: Self::Coordinate,
target: Self::Coordinate,
) -> Option<<Self::Axis as Axis>::Direction> { ... }
}
Expand description
Shape of the 2d lattice. It decides the behavior of the coordinate.
Required Associated Types§
Sourcetype Coordinate: Coordinate
type Coordinate: Coordinate
Coordinate of the lattice graph.
Sourcetype OffsetConvertError: Debug + Clone
type OffsetConvertError: Debug + Clone
Error to return when to_offset
fails.
Should set Infallible
when the graph is looped and never to fail.
Sourcetype CoordinateMoveError: Debug + Clone
type CoordinateMoveError: Debug + Clone
Error to return when move_coord
fails.
Should set Infallible
when the graph is looped and never to fail.
Required Methods§
Sourcefn horizontal(&self) -> usize
fn horizontal(&self) -> usize
Horizontal node count.
Sourcefn to_offset(
&self,
coord: Self::Coordinate,
) -> Result<Offset, Self::OffsetConvertError>
fn to_offset( &self, coord: Self::Coordinate, ) -> Result<Offset, Self::OffsetConvertError>
Convert coordinate to Offset
.
Sourcefn offset_to_coordinate(&self, offset: Offset) -> Self::Coordinate
fn offset_to_coordinate(&self, offset: Offset) -> Self::Coordinate
Convert coordinate from Offset
.
Sourcefn move_coord(
&self,
coord: Self::Coordinate,
dir: <Self::Axis as Axis>::Direction,
) -> Result<Self::Coordinate, Self::CoordinateMoveError>
fn move_coord( &self, coord: Self::Coordinate, dir: <Self::Axis as Axis>::Direction, ) -> Result<Self::Coordinate, Self::CoordinateMoveError>
Move coordinates to the next coordinate in the direction.
Coordinate should be a valid coordinate and should be checked before using move_coord
.
This is because the target coordinate might be valid even thought the souce coord is invalid,
and some code validate the direction by moveing the coord.
Provided Methods§
Sourcefn node_count(&self) -> usize
fn node_count(&self) -> usize
Node count.
Sourceunsafe fn to_offset_unchecked(&self, coord: Self::Coordinate) -> Offset
unsafe fn to_offset_unchecked(&self, coord: Self::Coordinate) -> Offset
Convert coordinate to Offset without a check.
Sourcefn index_to_coordinate(&self, index: usize) -> Self::Coordinate
fn index_to_coordinate(&self, index: usize) -> Self::Coordinate
Convert coordinate from index.
Sourcefn to_index(&self, coord: Self::Coordinate) -> Option<usize>
fn to_index(&self, coord: Self::Coordinate) -> Option<usize>
Covert coordinate to index.
Sourcefn index_to_offset(&self, index: usize) -> Offset
fn index_to_offset(&self, index: usize) -> Offset
Convert index to offset.
Sourcefn offset_to_index(&self, o: Offset) -> usize
fn offset_to_index(&self, o: Offset) -> usize
Covert offset to index.
Sourcefn horizontal_edge_size(&self, _axis: Self::Axis) -> usize
👎Deprecated
fn horizontal_edge_size(&self, _axis: Self::Axis) -> usize
Edge count of horizontal. May differ by the axis info.
Sourcefn vertical_edge_size(&self, _axis: Self::Axis) -> usize
👎Deprecated
fn vertical_edge_size(&self, _axis: Self::Axis) -> usize
Edge count of vertical. May differ by the axis info.
Sourceunsafe fn move_coord_unchecked(
&self,
coord: Self::Coordinate,
dir: <Self::Axis as Axis>::Direction,
) -> Self::Coordinate
unsafe fn move_coord_unchecked( &self, coord: Self::Coordinate, dir: <Self::Axis as Axis>::Direction, ) -> Self::Coordinate
Move coordinates to the next coordinate in the direction. Caller should be sure that the source and the target coord is valid coord.
Sourcefn is_neighbor(&self, a: Self::Coordinate, b: Self::Coordinate) -> bool
fn is_neighbor(&self, a: Self::Coordinate, b: Self::Coordinate) -> bool
Check whether two coordinate is in neighbor.
Sourcefn get_direction(
&self,
source: Self::Coordinate,
target: Self::Coordinate,
) -> Option<<Self::Axis as Axis>::Direction>
fn get_direction( &self, source: Self::Coordinate, target: Self::Coordinate, ) -> Option<<Self::Axis as Axis>::Direction>
Get direction if two coordiante is in neighbor.
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.