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>
impl<T> FixedVec2D<T>
Sourcepub unsafe fn from_raw(h: NonZeroUsize, v: usize, vec: Vec<T>) -> Option<Self>
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()
Sourcepub unsafe fn new_uninit(h: NonZeroUsize, v: usize) -> Self
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
.
Sourcepub fn new<F: FnMut(usize, usize) -> T>(h: NonZeroUsize, v: usize, f: F) -> Self
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));
}
}
Sourcepub fn mut_2d<'a>(&mut self) -> &mut [&'a mut [T]]
pub fn mut_2d<'a>(&mut self) -> &mut [&'a mut [T]]
Returns the mutable reference of this array.
Sourcepub fn into_raw(self) -> Vec<T>
pub fn into_raw(self) -> Vec<T>
Returns the underlying Vec
consuming this FixedVec2D
Sourcepub unsafe fn forget_values(&mut self)
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>>
impl<T> FixedVec2D<MaybeUninit<T>>
Sourcepub unsafe fn assume_init(self) -> FixedVec2D<T>
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>
impl<'a, T> AsMut<[&'a mut [T]]> for FixedVec2D<T>
Source§impl<T> AsMut<[T]> for FixedVec2D<T>
impl<T> AsMut<[T]> for FixedVec2D<T>
Source§impl<'a, T> AsRef<[&'a [T]]> for FixedVec2D<T>
impl<'a, T> AsRef<[&'a [T]]> for FixedVec2D<T>
Source§impl<T> AsRef<[T]> for FixedVec2D<T>
impl<T> AsRef<[T]> for FixedVec2D<T>
Source§impl<T: Clone> Clone for FixedVec2D<T>
impl<T: Clone> Clone for FixedVec2D<T>
Source§impl<T: Debug> Debug for FixedVec2D<T>
impl<T: Debug> Debug for FixedVec2D<T>
Source§impl<T> Drop for FixedVec2D<T>
impl<T> Drop for FixedVec2D<T>
Source§impl<T: Hash> Hash for FixedVec2D<T>
impl<T: Hash> Hash for FixedVec2D<T>
Source§impl<T: PartialEq> PartialEq for FixedVec2D<T>
impl<T: PartialEq> PartialEq for FixedVec2D<T>
impl<T: PartialEq> Eq for FixedVec2D<T>
impl<T: Send> Send for FixedVec2D<T>
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> 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
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> ConstOrValue<T> for T
impl<T> ConstOrValue<T> for T
Source§const IS_CONST_WRAP: bool = false
const IS_CONST_WRAP: bool = false
get wheter the type is const generic wrapper.
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
Compare self to
key
and return true
if they are equal.