pub struct RepeatArray<T> { /* private fields */ }Expand description
The RepeatArray struct represents an array that contains a single value repeated a specified
number of times.
Properties:
value: Thevalueproperty is a generic typeTthat represents the value that will be repeated in the array.size: Thesizeproperty represents the number of elements in the array.
Implementations§
Source§impl<T: Copy> RepeatArray<T>
impl<T: Copy> RepeatArray<T>
Sourcepub fn new(value: T, size: usize) -> RepeatArray<T>
pub fn new(value: T, size: usize) -> RepeatArray<T>
The function creates a new RepeatArray with a given value and size.
Arguments:
value: The value parameter is the value that will be repeated in the array.size: Thesizeparameter represents the desired size of theRepeatArray. It specifies the number of elements that theRepeatArrayshould contain.
Returns:
The new function is returning an instance of the RepeatArray<T> struct.
Examples:
use mywheel_rs::array_like::RepeatArray;
let array = RepeatArray::new(1, 5);
assert_eq!(array.len(), 5);
assert_eq!(array[0], 1);
assert_eq!(array[1], 1);pub fn get(&self, _index: usize) -> T
pub fn iter(&self) -> RepeatArrayIterator<T> ⓘ
pub fn len(&self) -> usize
Trait Implementations§
Source§impl<T: Copy> Index<usize> for RepeatArray<T>
impl<T: Copy> Index<usize> for RepeatArray<T>
Source§fn index(&self, _index: usize) -> &Self::Output
fn index(&self, _index: usize) -> &Self::Output
The index function returns a reference to the value at the specified index.
Arguments:
_index: The_indexparameter is of typeusize, which represents an index value used to access elements in a collection or array.
Returns:
The method is returning a reference to the value stored in the self object.
Examples:
use mywheel_rs::array_like::RepeatArray;
let array = RepeatArray::new(1, 5);
assert_eq!(array[0], 1);
assert_eq!(array[1], 1);Auto Trait Implementations§
impl<T> Freeze for RepeatArray<T>where
T: Freeze,
impl<T> RefUnwindSafe for RepeatArray<T>where
T: RefUnwindSafe,
impl<T> Send for RepeatArray<T>where
T: Send,
impl<T> Sync for RepeatArray<T>where
T: Sync,
impl<T> Unpin for RepeatArray<T>where
T: Unpin,
impl<T> UnwindSafe for RepeatArray<T>where
T: UnwindSafe,
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
Mutably borrows from an owned value. Read more