#[repr(transparent)]
pub struct IndexSlice<I, T> where
    I: Idx,
    T: ?Sized
{ pub raw: T, /* private fields */ }
Expand description

A slice that only accepts indices of a specific type. Note that the intended usage is as IndexSlice<I, [T]>.

This is a thin wrapper around a [T], to the point where the backing is a public property (called raw). This is in part because I know this API is not a complete mirror of Vec’s (patches welcome). In the worst case, you can always do what you need to the slice itself.

Some notes on the APIs

  • Most of the Slice APIs are present.

    • Any that aren’t can be trivially accessed on the underlying raw field, which is public.
  • Apis that take or return usizes referring to the positions of items were replaced with ones that take Idx.

  • Apis that take R: RangeBounds<usize> take an IdxRangeBounds<I>, which is basically a RangeBounds<I>.

  • Apis that take SliceIndex<usize> take an IdxSliceIndex<I>, which is basically a SliceIndex<I>.

  • Most iterator functions where the_iter().enumerate() would refer to indices have been given _enumerated variants. E.g. IndexSlice::iter_enumerated, etc. This is because v.iter().enumerate() would be (usize, &T), but you want (I, &T).

The following extensions are added:

Fields

raw: T

Implementations

Construct a new IdxSlice by wrapping an existing slice.

Construct a new mutable IdxSlice by wrapping an existing mutable slice.

Construct a new IdxSlice by wrapping an existing slice.

Construct a new mutable IdxSlice by wrapping an existing mutable slice.

Copies self into a new IndexVec.

Converts self into a vector without clones or allocation.

The resulting vector can be converted back into a box via IndexVec<I, T>’s into_boxed_slice method.

Returns the underlying slice.

Returns the underlying slice.

Returns an unsafe mutable pointer to the slice’s buffer.

Returns an unsafe pointer to the slice’s buffer.

Return the index of the last element, or panic.

Returns the length of our slice.

Returns the length of our slice as an I.

Returns true if we’re empty.

Get a iterator over reverences to our values.

See also IndexSlice::iter_enumerated, which gives you indices (of the correct type) as you iterate.

Get a iterator over mut reverences to our values.

See also IndexSlice::iter_mut_enumerated, which gives you indices (of the correct type) as you iterate.

Similar to self.iter().enumerate() but with indices of I and not usize.

Get an interator over all our indices.

Similar to self.iter_mut().enumerate() but with indices of I and not usize.

Forwards to the slice’s sort implementation.

Forwards to the slice’s sort_by implementation.

Forwards to the slice’s sort_by_key implementation.

Forwards to the slice’s sort_by_cached_key implementation.

Forwards to the slice’s sort_unstable implementation.

Forwards to the slice’s sort_unstable_by implementation.

Forwards to the slice’s sort_unstable_by_key implementation.

Forwards to the slice’s ends_with implementation.

Forwards to the slice’s starts_with implementation.

Forwards to the slice’s contains implementation.

Forwards to the slice’s reverse implementation.

Call slice::binary_search converting the indices it gives us back as needed.

Binary searches this sorted vec with a comparator function, converting the indices it gives us back to our Idx type.

Copies all elements from src into self, using a memcpy.

Copies the elements from src into self.

Swaps all elements in self with those in other.

Binary searches this sorted vec with a key extraction function, converting the indices it gives us back to our Idx type.

Searches for an element in an iterator, returning its index. This is equivalent to Iterator::position, but returns I and not usize.

Searches for an element in an iterator from the right, returning its index. This is equivalent to Iterator::position, but returns I and not usize.

Swaps two elements in our vector.

Divides our slice into two at an index.

Divides our slice into two at an index.

Rotates our data in-place such that the first mid elements of the slice move to the end while the last self.len() - mid elements move to the front

Rotates our data in-place such that the first self.len() - k elements of the slice move to the end while the last k elements move to the front

Return the the last element, if we are not empty.

Return the the last element, if we are not empty.

Return the the first element, if we are not empty.

Return the the first element, if we are not empty.

Copies elements from one part of the slice to another part of itself, using a memmove.

Get a ref to the item at the provided index, or None for out of bounds.

Get a mut ref to the item at the provided index, or None for out of bounds

Wraps the underlying slice’s windows iterator with one that yields IndexSlices with the correct index type.

Wraps the underlying slice’s chunks iterator with one that yields IndexSlices with the correct index type.

Wraps the underlying slice’s chunks_mut iterator with one that yields IndexSlices with the correct index type.

Wraps the underlying slice’s chunks_exact iterator with one that yields IndexSlices with the correct index type.

Wraps the underlying slice’s chunks_exact_mut iterator with one that yields IndexSlices with the correct index type.

Wraps the underlying slice’s rchunks iterator with one that yields IndexSlices with the correct index type.

Wraps the underlying slice’s rchunks_mut iterator with one that yields IndexSlices with the correct index type.

Wraps the underlying slice’s rchunks_exact iterator with one that yields IndexSlices with the correct index type.

Wraps the underlying slice’s rchunks_exact_mut iterator with one that yields IndexSlices with the correct index type.

Wraps the underlying slice’s split iterator with one that yields IndexSlices with the correct index type.

Wraps the underlying slice’s split_mut iterator with one that yields IndexSlices with the correct index type.

Wraps the underlying slice’s rsplit iterator with one that yields IndexSlices with the correct index type.

Wraps the underlying slice’s rsplit_mut iterator with one that yields IndexSlices with the correct index type.

Wraps the underlying slice’s splitn iterator with one that yields IndexSlices with the correct index type.

Wraps the underlying slice’s splitn_mut iterator with one that yields IndexSlices with the correct index type.

Wraps the underlying slice’s rsplitn iterator with one that yields IndexSlices with the correct index type.

Wraps the underlying slice’s rsplitn_mut iterator with one that yields IndexSlices with the correct index type.

Create a IdxSlice from its pointer and length.

Safety

This is equivalent to core::slice::from_raw_parts and has the same safety caveats.

Create a mutable IdxSlice from its pointer and length.

Safety

This is equivalent to core::slice::from_raw_parts_mut and has the same safety caveats.

Returns the first and all the rest of the elements of the slice, or None if it is empty.

Returns the first and all the rest of the elements of the slice, or None if it is empty.

Returns the last and all the rest of the elements of the slice, or None if it is empty.

Returns the last and all the rest of the elements of the slice, or None if it is empty.

Trait Implementations

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

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

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

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

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Returns a copy of the value. Read more

Performs copy-assignment from source. Read more

Returns a copy of the value. Read more

Performs copy-assignment from source. Read more

Formats the value using the given formatter. Read more

Returns the “default value” for a type. Read more

Returns the “default value” for a type. Read more

Returns the “default value” for a type. Read more

Deserialize this value from the given Serde deserializer. Read more

Converts to this type from the input type.

Converts to this type from the input type.

Converts to this type from the input type.

Converts to this type from the input type.

Converts to this type from the input type.

Converts to this type from the input type.

Creates a value from an iterator. Read more

Feeds this value into the given Hasher. Read more

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

The returned type after indexing.

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

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

The type of the elements being iterated over.

Which kind of iterator are we turning this into?

Creates an iterator from a value. Read more

The type of the elements being iterated over.

Which kind of iterator are we turning this into?

Creates an iterator from a value. Read more

The type of the elements being iterated over.

Which kind of iterator are we turning this into?

Creates an iterator from a value. Read more

This method returns an Ordering between self and other. Read more

Compares and returns the maximum of two values. Read more

Compares and returns the minimum of two values. Read more

Restrict a value to a certain interval. Read more

This method tests for self and other values to be equal, and is used by ==. Read more

This method tests for !=.

This method tests for self and other values to be equal, and is used by ==. Read more

This method tests for !=.

This method tests for self and other values to be equal, and is used by ==. Read more

This method tests for !=.

This method tests for self and other values to be equal, and is used by ==. Read more

This method tests for !=.

This method tests for self and other values to be equal, and is used by ==. Read more

This method tests for !=.

This method tests for self and other values to be equal, and is used by ==. Read more

This method tests for !=.

This method tests for self and other values to be equal, and is used by ==. Read more

This method tests for !=.

This method tests for self and other values to be equal, and is used by ==. Read more

This method tests for !=.

This method tests for self and other values to be equal, and is used by ==. Read more

This method tests for !=.

This method tests for self and other values to be equal, and is used by ==. Read more

This method tests for !=.

This method tests for self and other values to be equal, and is used by ==. Read more

This method tests for !=.

This method tests for self and other values to be equal, and is used by ==. Read more

This method tests for !=.

This method tests for self and other values to be equal, and is used by ==. Read more

This method tests for !=.

This method tests for self and other values to be equal, and is used by ==. Read more

This method tests for !=.

This method tests for self and other values to be equal, and is used by ==. Read more

This method tests for !=.

This method tests for self and other values to be equal, and is used by ==. Read more

This method tests for !=.

This method tests for self and other values to be equal, and is used by ==. Read more

This method tests for !=.

This method tests for self and other values to be equal, and is used by ==. Read more

This method tests for !=.

This method tests for self and other values to be equal, and is used by ==. Read more

This method tests for !=.

This method tests for self and other values to be equal, and is used by ==. Read more

This method tests for !=.

This method tests for self and other values to be equal, and is used by ==. Read more

This method tests for !=.

This method tests for self and other values to be equal, and is used by ==. Read more

This method tests for !=.

This method tests for self and other values to be equal, and is used by ==. Read more

This method tests for !=.

This method tests for self and other values to be equal, and is used by ==. Read more

This method tests for !=.

This method tests for self and other values to be equal, and is used by ==. Read more

This method tests for !=.

This method tests for self and other values to be equal, and is used by ==. Read more

This method tests for !=.

This method tests for self and other values to be equal, and is used by ==. Read more

This method tests for !=.

This method tests for self and other values to be equal, and is used by ==. Read more

This method tests for !=.

This method tests for self and other values to be equal, and is used by ==. Read more

This method tests for !=.

This method tests for self and other values to be equal, and is used by ==. Read more

This method tests for !=.

This method tests for self and other values to be equal, and is used by ==. Read more

This method tests for !=.

This method tests for self and other values to be equal, and is used by ==. Read more

This method tests for !=.

This method tests for self and other values to be equal, and is used by ==. Read more

This method tests for !=.

This method tests for self and other values to be equal, and is used by ==. Read more

This method tests for !=.

This method tests for self and other values to be equal, and is used by ==. Read more

This method tests for !=.

This method tests for self and other values to be equal, and is used by ==. Read more

This method tests for !=.

This method tests for self and other values to be equal, and is used by ==. Read more

This method tests for !=.

This method tests for self and other values to be equal, and is used by ==. Read more

This method tests for !=.

This method tests for self and other values to be equal, and is used by ==. Read more

This method tests for !=.

This method tests for self and other values to be equal, and is used by ==. Read more

This method tests for !=.

This method tests for self and other values to be equal, and is used by ==. Read more

This method tests for !=.

This method tests for self and other values to be equal, and is used by ==. Read more

This method tests for !=.

This method tests for self and other values to be equal, and is used by ==. Read more

This method tests for !=.

This method tests for self and other values to be equal, and is used by ==. Read more

This method tests for !=.

This method tests for self and other values to be equal, and is used by ==. Read more

This method tests for !=.

This method tests for self and other values to be equal, and is used by ==. Read more

This method tests for !=.

This method tests for self and other values to be equal, and is used by ==. Read more

This method tests for !=.

This method tests for self and other values to be equal, and is used by ==. Read more

This method tests for !=.

This method tests for self and other values to be equal, and is used by ==. Read more

This method tests for !=.

This method tests for self and other values to be equal, and is used by ==. Read more

This method tests for !=.

This method tests for self and other values to be equal, and is used by ==. Read more

This method tests for !=.

This method tests for self and other values to be equal, and is used by ==. Read more

This method tests for !=.

This method tests for self and other values to be equal, and is used by ==. Read more

This method tests for !=.

This method tests for self and other values to be equal, and is used by ==. Read more

This method tests for !=.

This method tests for self and other values to be equal, and is used by ==. Read more

This method tests for !=.

This method tests for self and other values to be equal, and is used by ==. Read more

This method tests for !=.

This method tests for self and other values to be equal, and is used by ==. Read more

This method tests for !=.

This method tests for self and other values to be equal, and is used by ==. Read more

This method tests for !=.

This method tests for self and other values to be equal, and is used by ==. Read more

This method tests for !=.

This method tests for self and other values to be equal, and is used by ==. Read more

This method tests for !=.

This method tests for self and other values to be equal, and is used by ==. Read more

This method tests for !=.

This method tests for self and other values to be equal, and is used by ==. Read more

This method tests for !=.

This method tests for self and other values to be equal, and is used by ==. Read more

This method tests for !=.

This method tests for self and other values to be equal, and is used by ==. Read more

This method tests for !=.

This method tests for self and other values to be equal, and is used by ==. Read more

This method tests for !=.

This method tests for self and other values to be equal, and is used by ==. Read more

This method tests for !=.

This method tests for self and other values to be equal, and is used by ==. Read more

This method tests for !=.

This method tests for self and other values to be equal, and is used by ==. Read more

This method tests for !=.

This method tests for self and other values to be equal, and is used by ==. Read more

This method tests for !=.

This method tests for self and other values to be equal, and is used by ==. Read more

This method tests for !=.

This method tests for self and other values to be equal, and is used by ==. Read more

This method tests for !=.

This method tests for self and other values to be equal, and is used by ==. Read more

This method tests for !=.

This method tests for self and other values to be equal, and is used by ==. Read more

This method tests for !=.

This method tests for self and other values to be equal, and is used by ==. Read more

This method tests for !=.

This method tests for self and other values to be equal, and is used by ==. Read more

This method tests for !=.

This method tests for self and other values to be equal, and is used by ==. Read more

This method tests for !=.

This method tests for self and other values to be equal, and is used by ==. Read more

This method tests for !=.

This method tests for self and other values to be equal, and is used by ==. Read more

This method tests for !=.

This method returns an ordering between self and other values if one exists. Read more

This method tests less than (for self and other) and is used by the < operator. Read more

This method tests less than or equal to (for self and other) and is used by the <= operator. Read more

This method tests greater than (for self and other) and is used by the > operator. Read more

This method tests greater than or equal to (for self and other) and is used by the >= operator. Read more

Serialize this value into the given Serde serializer. Read more

The resulting type after obtaining ownership.

Creates owned data from borrowed data, usually by cloning. Read more

Uses borrowed data to replace owned data, usually by cloning. Read more

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Convert Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>. Box<dyn Any> can then be further downcast into Box<ConcreteType> where ConcreteType implements Trait. Read more

Convert Rc<Trait> (where Trait: Downcast) to Rc<Any>. Rc<Any> can then be further downcast into Rc<ConcreteType> where ConcreteType implements Trait. Read more

Convert &Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot generate &Any’s vtable from &Trait’s. Read more

Convert &mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot generate &mut Any’s vtable from &mut Trait’s. Read more

Convert Arc<Trait> (where Trait: Downcast) to Arc<Any>. Arc<Any> can then be further downcast into Arc<ConcreteType> where ConcreteType implements Trait. Read more

Use this to cast from one trait object type to another. Read more

Use this to upcast a trait to one of its supertraits. Read more

Use this to cast from one trait object type to another. This method is more customizable than the dyn_cast method. Here you can also specify the “source” trait from which the cast is defined. This can for example allow using casts from a supertrait of the current trait object. Read more

Use this to cast from one trait object type to another. With this method the type parameter is a config type that uniquely specifies which cast should be preformed. Read more

Compare self to key and return true if they are equal.

Returns the argument unchanged.

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more

Instruments this type with the current Span, returning an Instrumented wrapper. Read more

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Should always be Self

The resulting type after obtaining ownership.

Creates owned data from borrowed data, usually by cloning. Read more

Uses borrowed data to replace owned data, usually by cloning. Read more

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more