pub struct WrappingIndex {
pub row: isize,
pub col: isize,
}
Expand description
A structure representing the wrapping index of an element in a
Matrix<T>
.
Unlike Index
, this type does not implement SingleElementIndex
,
and there is no wrapping equivalent for that trait. Additionally,
WrappingIndex
is the only type that exhibits wrapping indexing
behavior. You cannot pass a (isize, isize)
or a [isize; 2]
to
methods expecting an index, or more precisely, a type that implements
MatrixIndex<T>
.
The design choice is based on the following considerations
- Wrapping indexing does not follow standard indexing conventions, and should always be used explicitly.
- Both
(isize, isize)
and[isize; 2]
are not sufficiently distinguishable from theirusize
counterparts, which would introduce ambiguity and prevent type inference, making type annotations necessary.
Fields§
§row: isize
The row index of the element.
col: isize
The column index of the element.
Implementations§
Source§impl WrappingIndex
impl WrappingIndex
Trait Implementations§
Source§impl Clone for WrappingIndex
impl Clone for WrappingIndex
Source§fn clone(&self) -> WrappingIndex
fn clone(&self) -> WrappingIndex
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read moreSource§impl Debug for WrappingIndex
impl Debug for WrappingIndex
Source§impl Default for WrappingIndex
impl Default for WrappingIndex
Source§fn default() -> WrappingIndex
fn default() -> WrappingIndex
Source§impl<T> MatrixIndex<T> for WrappingIndex
impl<T> MatrixIndex<T> for WrappingIndex
Source§fn is_out_of_bounds(&self, matrix: &Matrix<T>) -> bool
fn is_out_of_bounds(&self, matrix: &Matrix<T>) -> bool
Returns true
if the index is out of bounds for the given matrix.
§Notes
A wrapping index is out of bounds if and only if the matrix is empty.
Source§unsafe fn get_unchecked(self, matrix: *const Matrix<T>) -> *const Self::Output
unsafe fn get_unchecked(self, matrix: *const Matrix<T>) -> *const Self::Output
Returns a pointer to the output at this location, without performing any bounds checking.
§Panics
Panics if the matrix is empty.
§Safety
Calling this method with a dangling matrix
pointer
is undefined behavior even if the resulting pointer is not used.
§Notes
If no panic occurs and no dangling pointer is passed, the output returned is guaranteed to be valid.
Source§unsafe fn get_unchecked_mut(self, matrix: *mut Matrix<T>) -> *mut Self::Output
unsafe fn get_unchecked_mut(self, matrix: *mut Matrix<T>) -> *mut Self::Output
Returns a mutable pointer to the output at this location, without performing any bounds checking.
§Panics
Panics if the matrix is empty.
§Safety
Calling this method with a dangling matrix
pointer
is undefined behavior even if the resulting pointer is not used.
§Notes
If no panic occurs and no dangling pointer is passed, the output returned is guaranteed to be valid.
Source§fn ensure_in_bounds(&self, matrix: &Matrix<T>) -> Result<&Self>
fn ensure_in_bounds(&self, matrix: &Matrix<T>) -> Result<&Self>
Source§fn get(self, matrix: &Matrix<T>) -> Result<&Self::Output>
fn get(self, matrix: &Matrix<T>) -> Result<&Self::Output>
Source§fn get_mut(self, matrix: &mut Matrix<T>) -> Result<&mut Self::Output>
fn get_mut(self, matrix: &mut Matrix<T>) -> Result<&mut Self::Output>
Source§impl PartialEq for WrappingIndex
impl PartialEq for WrappingIndex
impl Copy for WrappingIndex
impl Eq for WrappingIndex
impl StructuralPartialEq for WrappingIndex
Auto Trait Implementations§
impl Freeze for WrappingIndex
impl RefUnwindSafe for WrappingIndex
impl Send for WrappingIndex
impl Sync for WrappingIndex
impl Unpin for WrappingIndex
impl UnwindSafe for WrappingIndex
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self
into a Left
variant of Either<Self, Self>
if into_left
is true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self
into a Left
variant of Either<Self, Self>
if into_left(&self)
returns true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read more