Struct Index

Source
pub struct Index<LevelMask: BitBlock, LevelCount: ConstInteger>(/* private fields */);
Expand description

Range checked index.

Known to be within HibitTree<LevelMaskType, LevelCount>::index_range().

Whenever you see impl Into<Index<_, _>> - you can just use your usize index as usual.

Index range check is very cheap, and is just one assert_eq with constant value. But in tight loops you may want to get rid of that check - and that’s the sole purpose of Index.

// use it just as usize
array.get(12);

// zero-cost unsafe construction
array.get(unsafe{ Index::new_unchecked(12) });

// safe construct once, then reuse
{
    let i = Index::from(12);
    array.get(i);
    array2.get(i);
}

Implementations§

Source§

impl<LevelMaskType: BitBlock, LevelCount: ConstInteger> Index<LevelMaskType, LevelCount>

Source

pub unsafe fn new_unchecked(index: usize) -> Self

§Safety

You must guarantee that index is in SparseHierarchy<LevelMaskType, LevelCount> range.

Trait Implementations§

Source§

impl<LevelMask: BitBlock, LevelCount: ConstInteger> Clone for Index<LevelMask, LevelCount>

Source§

fn clone(&self) -> Self

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<LevelMaskType: BitBlock, LevelCount: ConstInteger> From<Index<LevelMaskType, LevelCount>> for usize

SparseHierarchyIndex -> usize

Source§

fn from(value: Index<LevelMaskType, LevelCount>) -> Self

Converts to this type from the input type.
Source§

impl<LevelMaskType: BitBlock, LevelCount: ConstInteger> From<usize> for Index<LevelMaskType, LevelCount>

usize -> SparseHierarchyIndex

Source§

fn from(index: usize) -> Self

§Panic

Panics if index is not in SparseHierarchy<LevelMaskType, LevelCount> range.

Source§

impl<LevelMask: BitBlock, LevelCount: ConstInteger> Copy for Index<LevelMask, LevelCount>

Auto Trait Implementations§

§

impl<LevelMask, LevelCount> Freeze for Index<LevelMask, LevelCount>

§

impl<LevelMask, LevelCount> RefUnwindSafe for Index<LevelMask, LevelCount>
where LevelMask: RefUnwindSafe, LevelCount: RefUnwindSafe,

§

impl<LevelMask, LevelCount> Send for Index<LevelMask, LevelCount>
where LevelMask: Send, LevelCount: Send,

§

impl<LevelMask, LevelCount> Sync for Index<LevelMask, LevelCount>
where LevelMask: Sync, LevelCount: Sync,

§

impl<LevelMask, LevelCount> Unpin for Index<LevelMask, LevelCount>
where LevelMask: Unpin, LevelCount: Unpin,

§

impl<LevelMask, LevelCount> UnwindSafe for Index<LevelMask, LevelCount>
where LevelMask: UnwindSafe, LevelCount: 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, 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> Take<T> for T

Source§

fn take(self) -> T

Takes self as T. Read more
Source§

fn try_take(self) -> Option<T>

Returned Option variant can be used for compile-time switch.
Source§

fn take_or_clone(self) -> T

Return self as is for T, clone for &T.
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.