Struct FixedVec2D

Source
pub struct FixedVec2D<T> { /* private fields */ }
Expand description

Raw fixed 2d vector. It has two axis, horizontal and vertical. Data is stored on one Vec. Horizontal size must not be 0.

Implementations§

Source§

impl<T> FixedVec2D<T>

Source

pub unsafe fn from_raw(h: NonZeroUsize, v: usize, vec: Vec<T>) -> Option<Self>

Creates a array2d with a vec. Returns None if h * v != vec.len()

Source

pub unsafe fn new_uninit(h: NonZeroUsize, v: usize) -> Self

Creates a FixedVec2D without initializing. It is unsafe to use it so I recomend to use with MaybeUninit or just use new. See assume_init.

Source

pub fn new<F: FnMut(usize, usize) -> T>(h: NonZeroUsize, v: usize, f: F) -> Self

Creates a FixedVec2D with initializing from the function.

let array = FixedVec2D::new(NonZeroUsize::new(5).unwrap(), 2, |h, v| (h, v));
for i in 0..5 {
    for j in 0..2 {
        assert_eq!(array.ref_2d()[i][j], (i, j));
    }
}
Source

pub fn h_size(&self) -> usize

Returns the horizontal size.

Source

pub fn v_size(&self) -> usize

Returns the vertical size.

Source

pub fn size(&self) -> usize

Returns the length of underlying Vec.

Source

pub fn ref_1d(&self) -> &[T]

Returns the slice of all values in the array.

Source

pub fn ref_2d<'a>(&self) -> &[&'a [T]]

Returns the reference of this array.

Source

pub fn mut_1d(&mut self) -> &mut [T]

Returns the mutable slice of all values in the array.

Source

pub fn mut_2d<'a>(&mut self) -> &mut [&'a mut [T]]

Returns the mutable reference of this array.

Source

pub fn into_raw(self) -> Vec<T>

Returns the underlying Vec consuming this FixedVec2D

Source

pub unsafe fn forget_values(&mut self)

Drop the heads vec and forget values. This is to drop the values manually in FixedVec2D. Should drop the values first and than use this method.

struct Flag{ pub drop_count : AtomicUsize }
impl Drop for Flag {
    fn drop(&mut self) {
        assert_eq!(self.drop_count.fetch_add(1, Ordering::SeqCst), 0);
    }
}

let mut vec = FixedVec2D::<Flag>::new(
    NonZeroUsize::new(4).unwrap(),
    3,
    |i,j| Flag{ drop_count : AtomicUsize::new(0) }
);

// manually drops
vec.mut_1d().iter_mut().for_each(|f| unsafe{ std::ptr::drop_in_place(f) });
// forget
unsafe { vec.forget_values() };
Source§

impl<T> FixedVec2D<MaybeUninit<T>>

Source

pub unsafe fn assume_init(self) -> FixedVec2D<T>

Assume init. Use this with new_uninit.

let mut array = unsafe { FixedVec2D::<MaybeUninit<i32>>::new_uninit(NonZeroUsize::new(6).unwrap(),3) };
for i in 0..6{
    for j in 0..3{
        array.mut_2d()[i][j] = MaybeUninit::new((i + j) as i32);
    }
}
let array_init = unsafe { array.assume_init() };

Trait Implementations§

Source§

impl<'a, T> AsMut<[&'a mut [T]]> for FixedVec2D<T>

Source§

fn as_mut(&mut self) -> &mut [&'a mut [T]]

Converts this type into a mutable reference of the (usually inferred) input type.
Source§

impl<T> AsMut<[T]> for FixedVec2D<T>

Source§

fn as_mut(&mut self) -> &mut [T]

Converts this type into a mutable reference of the (usually inferred) input type.
Source§

impl<'a, T> AsRef<[&'a [T]]> for FixedVec2D<T>

Source§

fn as_ref(&self) -> &[&'a [T]]

Converts this type into a shared reference of the (usually inferred) input type.
Source§

impl<T> AsRef<[T]> for FixedVec2D<T>

Source§

fn as_ref(&self) -> &[T]

Converts this type into a shared reference of the (usually inferred) input type.
Source§

impl<T: Clone> Clone for FixedVec2D<T>

Source§

fn clone(&self) -> Self

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 FixedVec2D<T>

Source§

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

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

impl<T> Drop for FixedVec2D<T>

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more
Source§

impl<T: Hash> Hash for FixedVec2D<T>

Source§

fn hash<H: Hasher>(&self, state: &mut H)

Feeds this value into the given Hasher. Read more
1.3.0 · Source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
Source§

impl<T> Index<(usize, usize)> for FixedVec2D<T>

Source§

type Output = T

The returned type after indexing.
Source§

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

Performs the indexing (container[index]) operation. Read more
Source§

impl<T> IndexMut<(usize, usize)> for FixedVec2D<T>

Source§

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

Performs the mutable indexing (container[index]) operation. Read more
Source§

impl<T: PartialEq> PartialEq for FixedVec2D<T>

Source§

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

Source§

impl<T: Send> Send for FixedVec2D<T>

Source§

impl<T: Sync> Sync for FixedVec2D<T>

Auto Trait Implementations§

§

impl<T> Freeze for FixedVec2D<T>

§

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

§

impl<T> Unpin for FixedVec2D<T>

§

impl<T> UnwindSafe for FixedVec2D<T>
where T: RefUnwindSafe,

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> ConstOrValue<T> for T

Source§

const IS_CONST_WRAP: bool = false

get wheter the type is const generic wrapper.
Source§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn equivalent(&self, key: &K) -> bool

Checks if this value is equivalent to the given key. Read more
Source§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn equivalent(&self, key: &K) -> bool

Compare self to key and return true if they are equal.
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.