Trait granite::MoveFix[][src]

pub trait MoveFix: Sized {
    unsafe fn fix_shift<S>(
        storage: &mut S,
        shifted_from: usize,
        shifted_by: NonZeroIsize
    )
    where
        S: ListStorage<Element = Self>
;
unsafe fn fix_move<S>(
        storage: &mut S,
        previous_index: usize,
        current_index: usize
    )
    where
        S: ListStorage<Element = Self>
; unsafe fn fix_left_shift<S>(
        storage: &mut S,
        shifted_from: usize,
        shifted_by: NonZeroUsize
    )
    where
        S: ListStorage<Element = Self>
, { ... }
unsafe fn fix_right_shift<S>(
        storage: &mut S,
        shifted_from: usize,
        shifted_by: NonZeroUsize
    )
    where
        S: ListStorage<Element = Self>
, { ... } }

Trait for data structure element types to be able to correct indices towards other elements when they are moved around in the collection.

See the documentation on the individual methods for more details on the semantics of those hooks.

Required methods

unsafe fn fix_shift<S>(
    storage: &mut S,
    shifted_from: usize,
    shifted_by: NonZeroIsize
) where
    S: ListStorage<Element = Self>, 
[src]

The hook to be called when the items in the collection get shifted due to an insertion or removal. shifted_from specifies the index from which the shift starts (first affected element), i.e. the index at which a new item was inserted or from which an item was removed. Positive values for shifted_by indicate a shift to the right, negative are to the left.

This method is never called directly by storages. fix_left_shift and fix_right_shift are called instead. See those for more on how and when this method gets called.

Safety

This method can only be called by fix_left_shift and fix_right_shift. All safety implications of those methods apply.

unsafe fn fix_move<S>(
    storage: &mut S,
    previous_index: usize,
    current_index: usize
) where
    S: ListStorage<Element = Self>, 
[src]

The hook to be called when an element in a collection gets moved from one location to another. previous_index represents its previous index before moving and is not guaranteed to be a valid index, current_index is its new index and is guaranteed to point towards a valid element.

Safety

The implementor of this method may cause undefined behavior if the method was called erroneously and elements were not actually swapped.

Loading content...

Provided methods

unsafe fn fix_left_shift<S>(
    storage: &mut S,
    shifted_from: usize,
    shifted_by: NonZeroUsize
) where
    S: ListStorage<Element = Self>, 
[src]

The hook to be called when the items in the collection get shifted to the left due to a removal. shifted_from specifies the index from which the shift starts (first affected element), i.e. the index from which an item was removed.

Safety

The implementor of this method may cause undefined behavior if the method was called erroneously and elements were not actually shifted.

Panics

Required to panic on integer overflow when converting the shifted_by into a NonZeroIsize.

unsafe fn fix_right_shift<S>(
    storage: &mut S,
    shifted_from: usize,
    shifted_by: NonZeroUsize
) where
    S: ListStorage<Element = Self>, 
[src]

The hook to be called when the items in the collection get shifted to the right due to an insertion. shifted_from specifies the index from which the shift starts (first affected element), i.e. the index at which a new item was inserted.

Safety

The implementor of this method may cause undefined behavior if the method was called erroneously and elements were not actually shifted.

Loading content...

Implementors

impl<T> MoveFix for DummyMoveFix<T>[src]

Dummy implementation, does nothing when notified.

Loading content...