ShiftArray

Struct ShiftArray 

Source
pub struct ShiftArray<T> {
    pub start: usize,
    pub lst: Vec<T>,
}
Expand description

The ShiftArray type represents an array that can be shifted to the left or right without copying or moving its elements.

Properties:

  • start: The start property represents the index of the first element in the ShiftArray. It indicates the starting point from which elements are accessed or shifted.
  • lst: The lst property is a vector that holds the elements of the ShiftArray. It is of type Vec<T>, where T is a generic type parameter that can be replaced with any type.

Fields§

§start: usize§lst: Vec<T>

Implementations§

Source§

impl<T> ShiftArray<T>

Source

pub fn new(lst: Vec<T>) -> Self

The function “new” initializes a new instance of a struct with a starting index of 0 and a given list.

Arguments:

  • lst: The lst parameter is a Vec<T>, which is a vector of elements of type T.

Returns:

The new function is returning an instance of the struct that it is defined in.

Examples:

use mywheel_rs::array_like::ShiftArray;

let mut shift_array = ShiftArray::new(vec![1, 2, 3]);
assert_eq!(shift_array.start, 0);
assert_eq!(shift_array.lst, vec![1, 2, 3]);
assert_eq!(shift_array.len(), 3);
assert_eq!(shift_array[0], 1);
Source

pub fn set_start(&mut self, start: usize)

The function sets the start value of a variable.

Arguments:

  • start: The start parameter is of type usize, which represents an unsigned integer that can hold the size of any object in memory. It is used to set the value of the start field in the struct or object that this method belongs to.
§Examples
use mywheel_rs::array_like::ShiftArray;

let mut shift_array = ShiftArray::new(vec![1, 2, 3]);
shift_array.set_start(1);
assert_eq!(shift_array.start, 1);
assert_eq!(shift_array.len(), 3);
Source

pub fn items(&self) -> impl Iterator<Item = (usize, &T)>

The items function returns an iterator that yields the index and reference to each element in the lst vector, with the index adjusted by the start value.

§Examples
use mywheel_rs::array_like::ShiftArray;
let mut shift_array = ShiftArray::new(vec![1, 2, 3]);
shift_array.set_start(1);
for (i, v) in shift_array.items() {
    assert_eq!(i, *v as usize);
}
Source

pub fn iter(&self) -> ShiftArrayIterator<'_, T>

Source

pub fn len(&self) -> usize

Trait Implementations§

Source§

impl<T: Clone> Clone for ShiftArray<T>

Source§

fn clone(&self) -> ShiftArray<T>

Returns a duplicate 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<T: Debug> Debug for ShiftArray<T>

Source§

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

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

impl<T> Index<usize> for ShiftArray<T>

Source§

fn index(&self, key: usize) -> &Self::Output

The index function returns a reference to an element in a list based on a given key.

Arguments:

  • key: The key parameter is of type usize and represents the index of the element to be accessed in the lst field.

Returns:

The method index returns a reference to an element of self.lst at the specified index key - self.start.

§Examples
use mywheel_rs::array_like::ShiftArray;
let mut shift_array = ShiftArray::new(vec![1, 2, 3]);
assert_eq!(shift_array[2], 3);
shift_array.set_start(1);
assert_eq!(shift_array[2], 2);
Source§

type Output = T

The returned type after indexing.
Source§

impl<T> IndexMut<usize> for ShiftArray<T>

Source§

fn index_mut(&mut self, key: usize) -> &mut Self::Output

The function index_mut returns a mutable reference to an element in a list based on a given key.

Arguments:

  • key: The key parameter is of type usize and represents the index of the element to be accessed in the lst vector.

Returns:

A mutable reference to an element in the lst vector, located at the index key - self.start.

§Examples
use mywheel_rs::array_like::ShiftArray;
let mut shift_array = ShiftArray::new(vec![1, 2, 3]);
assert_eq!(shift_array[2], 3);
shift_array.set_start(1);
assert_eq!(shift_array[2], 2);
shift_array[2] = 4;
assert_eq!(shift_array[2], 4);
Source§

impl<T: PartialEq> PartialEq for ShiftArray<T>

Source§

fn eq(&self, other: &ShiftArray<T>) -> 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<T: Eq> Eq for ShiftArray<T>

Source§

impl<T> StructuralPartialEq for ShiftArray<T>

Auto Trait Implementations§

§

impl<T> Freeze for ShiftArray<T>

§

impl<T> RefUnwindSafe for ShiftArray<T>
where T: RefUnwindSafe,

§

impl<T> Send for ShiftArray<T>
where T: Send,

§

impl<T> Sync for ShiftArray<T>
where T: Sync,

§

impl<T> Unpin for ShiftArray<T>
where T: Unpin,

§

impl<T> UnwindSafe for ShiftArray<T>
where T: UnwindSafe,

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

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