Struct WrappingIndex

Source
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 their usize 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

Source

pub fn new(row: isize, col: isize) -> Self

Creates a new WrappingIndex.

§Examples
use matreex::WrappingIndex;

let index = WrappingIndex::new(2, 3);
assert_eq!(index.row, 2);
assert_eq!(index.col, 3);
Source

pub fn swap(&mut self) -> &mut Self

Swaps the row and column indices.

§Examples
use matreex::WrappingIndex;

let mut index = WrappingIndex::new(2, 3);
index.swap();
assert_eq!(index, WrappingIndex::new(3, 2));

Trait Implementations§

Source§

impl Clone for WrappingIndex

Source§

fn clone(&self) -> WrappingIndex

Returns a copy of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for WrappingIndex

Source§

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

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

impl Default for WrappingIndex

Source§

fn default() -> WrappingIndex

Returns the “default value” for a type. Read more
Source§

impl From<[isize; 2]> for WrappingIndex

Source§

fn from(value: [isize; 2]) -> Self

Converts to this type from the input type.
Source§

impl From<(isize, isize)> for WrappingIndex

Source§

fn from(value: (isize, isize)) -> Self

Converts to this type from the input type.
Source§

impl<T> MatrixIndex<T> for WrappingIndex

Source§

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

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

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§

type Output = T

The output type returned by methods.
Source§

fn ensure_in_bounds(&self, matrix: &Matrix<T>) -> Result<&Self>

Ensures the index is in bounds for the given matrix. Read more
Source§

fn get(self, matrix: &Matrix<T>) -> Result<&Self::Output>

Returns a shared reference to the output at this location, if in bounds. Read more
Source§

fn get_mut(self, matrix: &mut Matrix<T>) -> Result<&mut Self::Output>

Returns a mutable reference to the output at this location, if in bounds. Read more
Source§

fn index(self, matrix: &Matrix<T>) -> &Self::Output

Returns a shared reference to the output at this location. Read more
Source§

fn index_mut(self, matrix: &mut Matrix<T>) -> &mut Self::Output

Returns a mutable reference to the output at this location. Read more
Source§

impl PartialEq for WrappingIndex

Source§

fn eq(&self, other: &WrappingIndex) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

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 Copy for WrappingIndex

Source§

impl Eq for WrappingIndex

Source§

impl StructuralPartialEq for WrappingIndex

Auto Trait Implementations§

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, dst: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dst. 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> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts 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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts 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
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
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, 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.