#[repr(transparent)]pub struct TiVec<K, V> {
pub raw: Vec<V>,
/* private fields */
}
alloc
only.Expand description
A contiguous growable array type
that only accepts keys of the type K
.
TiVec<K, V>
is a wrapper around Rust container type std::vec::Vec
.
The struct mirrors the stable API of Rust std::vec::Vec
and forwards to it as much as possible.
TiVec<K, V>
uses K
instead of usize
for element indices and
require the index to implement
From<usize>
and Into<usize>
traits.
Their implementation can be easily done
with derive_more
crate and #[derive(From, Into)]
.
TiVec<K, V>
can be converted to std::vec::Vec<V>
and
back using From
and Into
.
There are also zero-cost conversions available between references:
&std::vec::Vec<V>
and&TiVec<K, V>
withAsRef
,&mut std::vec::Vec<V>
and&mut TiVec<K, V>
withAsMut
,
Added methods:
from_ref
- Converts a&std::vec::Vec<V>
into a&TiVec<K, V>
.from_mut
- Converts a&mut std::vec::Vec<V>
into a&mut TiVec<K, V>
.push_and_get_key
- Appends an element to the back of a collection and returns its index of typeK
.pop_key_value
- Removes the last element from a vector and returns it with its index of typeK
, orNone
if the vector is empty.drain_enumerated
- Creates a draining iterator that removes the specified range in the vector and yields the current count and the removed items. It acts likeself.drain(range).enumerate()
, but instead ofusize
it returns index of typeK
.into_iter_enumerated
- Converts the vector into iterator over all key-value pairs withK
used for iteration indices. It acts likeself.into_iter().enumerate()
, but useK
instead ofusize
for iteration indices.
§Example
use derive_more::{From, Into};
use typed_index_collections::TiVec;
#[derive(From, Into)]
struct FooId(usize);
let mut foos: TiVec<FooId, usize> = std::vec![10, 11, 13].into();
foos.insert(FooId(2), 12);
assert_eq!(foos[FooId(2)], 12);
Fields§
§raw: Vec<V>
Raw slice property
Implementations§
Source§impl<K, V> TiVec<K, V>
impl<K, V> TiVec<K, V>
Sourcepub fn with_capacity(capacity: usize) -> Self
pub fn with_capacity(capacity: usize) -> Self
Constructs a new, empty TiVec<K, V>
with the specified capacity.
See Vec::with_capacity
for more details.
Sourcepub unsafe fn from_raw_parts(
ptr: *mut V,
length: usize,
capacity: usize,
) -> Self
pub unsafe fn from_raw_parts( ptr: *mut V, length: usize, capacity: usize, ) -> Self
Creates a TiVec<K, V>
directly from the raw components of another
vector.
See Vec::from_raw_parts
for more details.
§Safety
This is highly unsafe, due to the number of invariants that aren’t
checked.
See Vec::from_raw_parts
for more details.
Sourcepub const fn from_ref(raw: &Vec<V>) -> &Self
pub const fn from_ref(raw: &Vec<V>) -> &Self
Converts a &std::vec::Vec<V>
into a &TiVec<K, V>
.
Vector reference is intentionally used in the argument instead of slice reference for conversion with no-op.
§Example
pub struct Id(usize);
let vec: &TiVec<Id, usize> = TiVec::from_ref(&vec![1, 2, 4]);
Sourcepub fn from_mut(raw: &mut Vec<V>) -> &mut Self
pub fn from_mut(raw: &mut Vec<V>) -> &mut Self
Converts a &mut std::vec::Vec<V>
into a &mut TiVec<K, V>
.
§Example
pub struct Id(usize);
let vec: &mut TiVec<Id, usize> = TiVec::from_mut(&mut vec![1, 2, 4]);
Sourcepub fn capacity(&self) -> usize
pub fn capacity(&self) -> usize
Returns the number of elements the vector can hold without reallocating.
See Vec::capacity
for more details.
Sourcepub fn reserve(&mut self, additional: usize)
pub fn reserve(&mut self, additional: usize)
Reserves capacity for at least additional
more elements to be inserted
in the given TiVec<K, V>
. The collection may reserve more space to
avoid frequent reallocations. After calling reserve
, capacity will
be greater than or equal to self.len() + additional
. Does nothing
if capacity is already sufficient.
See Vec::reserve
for more details.
Sourcepub fn reserve_exact(&mut self, additional: usize)
pub fn reserve_exact(&mut self, additional: usize)
Reserves the minimum capacity for exactly additional
more elements to
be inserted in the given TiVec<K, V>
. After calling reserve_exact
,
capacity will be greater than or equal to self.len() + additional
.
Does nothing if the capacity is already sufficient.
See Vec::reserve_exact
for more details.
Sourcepub fn try_reserve(&mut self, additional: usize) -> Result<(), TryReserveError>
pub fn try_reserve(&mut self, additional: usize) -> Result<(), TryReserveError>
Tries to reserve capacity for at least additional
more elements to be
inserted in the given Vec<T>
.
See Vec::try_reserve
for more details.
§Errors
If the capacity overflows, or the allocator reports a failure, then an error is returned.
Sourcepub fn try_reserve_exact(
&mut self,
additional: usize,
) -> Result<(), TryReserveError>
pub fn try_reserve_exact( &mut self, additional: usize, ) -> Result<(), TryReserveError>
Tries to reserve the minimum capacity for at least additional
elements to be inserted in the given Vec<T>
.
See Vec::try_reserve_exact
for more details.
§Errors
If the capacity overflows, or the allocator reports a failure, then an error is returned.
Sourcepub fn shrink_to_fit(&mut self)
pub fn shrink_to_fit(&mut self)
Shrinks the capacity of the vector as much as possible.
See Vec::shrink_to_fit
for more details.
Sourcepub fn shrink_to(&mut self, min_capacity: usize)
pub fn shrink_to(&mut self, min_capacity: usize)
Shrinks the capacity of the vector with a lower bound.
See Vec::shrink_to
for more details.
Sourcepub fn into_boxed_slice(self) -> Box<TiSlice<K, V>>
pub fn into_boxed_slice(self) -> Box<TiSlice<K, V>>
Converts the vector into Box<TiSlice<K, V>>
.
See Vec::into_boxed_slice
for more details.
Sourcepub fn truncate(&mut self, len: usize)
pub fn truncate(&mut self, len: usize)
Shortens the vector, keeping the first len
elements and dropping
the rest.
See Vec::truncate
for more details.
Sourcepub fn as_slice(&self) -> &TiSlice<K, V>
pub fn as_slice(&self) -> &TiSlice<K, V>
Extracts a slice containing the entire vector.
See Vec::as_slice
for more details.
Sourcepub fn as_mut_slice(&mut self) -> &mut TiSlice<K, V>
pub fn as_mut_slice(&mut self) -> &mut TiSlice<K, V>
Extracts a mutable slice of the entire vector.
See Vec::as_mut_slice
for more details.
Sourcepub fn as_ptr(&self) -> *const V
pub fn as_ptr(&self) -> *const V
Returns a raw pointer to the vector’s buffer.
See Vec::as_ptr
for more details.
Sourcepub fn as_mut_ptr(&mut self) -> *mut V
pub fn as_mut_ptr(&mut self) -> *mut V
Returns an unsafe mutable pointer to the vector’s buffer.
See Vec::as_mut_ptr
for more details.
Sourcepub unsafe fn set_len(&mut self, new_len: usize)
pub unsafe fn set_len(&mut self, new_len: usize)
Forces the length of the vector to new_len
.
See Vec::set_len
for more details.
§Safety
new_len
must be less than or equal tocapacity()
.- The elements at
old_len..new_len
must be initialized.
Sourcepub fn swap_remove(&mut self, index: K) -> V
pub fn swap_remove(&mut self, index: K) -> V
Removes an element from the vector and returns it.
The removed element is replaced by the last element of the vector.
See Vec::swap_remove
for more details.
Sourcepub fn insert(&mut self, index: K, element: V)
pub fn insert(&mut self, index: K, element: V)
Inserts an element at position index
within the vector, shifting all
elements after it to the right.
See Vec::insert
for more details.
Sourcepub fn remove(&mut self, index: K) -> V
pub fn remove(&mut self, index: K) -> V
Removes and returns the element at position index
within the vector,
shifting all elements after it to the left.
See Vec::remove
for more details.
Sourcepub fn retain<F>(&mut self, f: F)
pub fn retain<F>(&mut self, f: F)
Retains only the elements specified by the predicate.
See Vec::retain
for more details.
Sourcepub fn retain_mut<F>(&mut self, f: F)
pub fn retain_mut<F>(&mut self, f: F)
Retains only the elements specified by the predicate, passing a mutable reference to it.
See Vec::retain_mut
for more details.
Sourcepub fn dedup_by_key<F, K2>(&mut self, key: F)
pub fn dedup_by_key<F, K2>(&mut self, key: F)
Removes all but the first of consecutive elements in the vector that resolve to the same key.
See Vec::dedup_by_key
for more details.
Sourcepub fn dedup_by<F>(&mut self, same_bucket: F)
pub fn dedup_by<F>(&mut self, same_bucket: F)
Removes all but the first of consecutive elements in the vector satisfying a given equality relation.
See Vec::dedup_by
for more details.
Sourcepub fn push(&mut self, value: V)
pub fn push(&mut self, value: V)
Appends an element to the back of a collection.
See Vec::push
for more details.
Sourcepub fn push_and_get_key(&mut self, value: V) -> K
pub fn push_and_get_key(&mut self, value: V) -> K
Appends an element to the back of a collection and returns its index of
type K
.
It acts like { vec.push(...); vec.last_key().unwrap() }
,
but is optimized better.
See Vec::push
for more details.
§Example
#[derive(Eq, Debug, From, Into, PartialEq)]
pub struct Id(usize);
let mut vec: TiVec<Id, usize> = vec![1, 2, 4].into();
assert_eq!(vec.push_and_get_key(8), Id(3));
assert_eq!(vec.push_and_get_key(16), Id(4));
assert_eq!(vec.push_and_get_key(32), Id(5));
Sourcepub fn pop_key_value(&mut self) -> Option<(K, V)>
pub fn pop_key_value(&mut self) -> Option<(K, V)>
Removes the last element from a vector and returns it with
its index of type K
, or None
if the vector is empty.
See Vec::pop
for more details.
§Example
#[derive(Eq, Debug, From, Into, PartialEq)]
pub struct Id(usize);
let mut vec: TiVec<Id, usize> = vec![1, 2, 4].into();
assert_eq!(vec.pop_key_value(), Some((Id(2), 4)));
assert_eq!(vec.pop_key_value(), Some((Id(1), 2)));
assert_eq!(vec.pop_key_value(), Some((Id(0), 1)));
assert_eq!(vec.pop_key_value(), None);
Sourcepub fn append(&mut self, other: &mut Self)
pub fn append(&mut self, other: &mut Self)
Moves all the elements of other
into Self
, leaving other
empty.
See Vec::append
for more details.
Sourcepub fn drain<R>(&mut self, range: R) -> Drain<'_, V> ⓘwhere
R: TiRangeBounds<K>,
pub fn drain<R>(&mut self, range: R) -> Drain<'_, V> ⓘwhere
R: TiRangeBounds<K>,
Creates a draining iterator that removes the specified range in the vector and yields the removed items.
See Vec::drain
for more details.
Sourcepub fn drain_enumerated<R>(
&mut self,
range: R,
) -> TiEnumerated<Drain<'_, V>, K, V>
pub fn drain_enumerated<R>( &mut self, range: R, ) -> TiEnumerated<Drain<'_, V>, K, V>
Creates a draining iterator that removes the specified range in the vector and yields the current count and the removed items.
It acts like self.drain(range).enumerate()
,
but instead of usize
it returns index of type K
.
Note that the indices started from K::from_usize(0)
,
regardless of the range starting point.
See Vec::drain
for more details.
§Example
#[derive(Eq, Debug, From, Into, PartialEq)]
pub struct Id(usize);
let mut vec: TiVec<Id, usize> = vec![1, 2, 4].into();
{
let mut iterator = vec.drain_enumerated(Id(1)..);
assert_eq!(iterator.next(), Some((Id(0), 2)));
assert_eq!(iterator.next(), Some((Id(1), 4)));
assert_eq!(iterator.next(), None);
}
assert_eq!(vec.as_slice(), TiSlice::from_ref(&[1]));
Sourcepub fn clear(&mut self)
pub fn clear(&mut self)
Clears the vector, removing all values.
See Vec::clear
for more details.
Sourcepub fn len(&self) -> usize
pub fn len(&self) -> usize
Returns the number of elements in the vector, also referred to as its ‘length’.
See Vec::len
for more details.
Sourcepub fn is_empty(&self) -> bool
pub fn is_empty(&self) -> bool
Returns true
if the vector contains no elements.
See Vec::is_empty
for more details.
Sourcepub fn split_off(&mut self, at: K) -> Self
pub fn split_off(&mut self, at: K) -> Self
Splits the collection into two at the given index.
See Vec::split_off
for more details.
Sourcepub fn resize_with<F>(&mut self, new_len: usize, f: F)where
F: FnMut() -> V,
pub fn resize_with<F>(&mut self, new_len: usize, f: F)where
F: FnMut() -> V,
Resizes the TiVec
in-place so that len
is equal to new_len
.
See Vec::resize_with
for more details.
Sourcepub fn resize(&mut self, new_len: usize, value: V)where
V: Clone,
pub fn resize(&mut self, new_len: usize, value: V)where
V: Clone,
Resizes the TiVec
in-place so that len
is equal to new_len
.
See Vec::resize
for more details.
Sourcepub fn leak<'a>(self) -> &'a mut TiSlice<K, V>
pub fn leak<'a>(self) -> &'a mut TiSlice<K, V>
Consumes and leaks the Vec
, returning a mutable reference to the
contents, &'a mut [T]
. Note that the type T
must outlive the
chosen lifetime 'a
. If the type has only static references, or
none at all, then this may be chosen to be 'static
.
See Vec::leak
for more details.
Sourcepub fn spare_capacity_mut(&mut self) -> &mut TiSlice<K, MaybeUninit<V>>
pub fn spare_capacity_mut(&mut self) -> &mut TiSlice<K, MaybeUninit<V>>
Returns the remaining spare capacity of the vector as a slice of
MaybeUninit<T>
.
See Vec::spare_capacity_mut
for more details.
Sourcepub fn extend_from_slice(&mut self, other: &TiSlice<K, V>)where
V: Clone,
pub fn extend_from_slice(&mut self, other: &TiSlice<K, V>)where
V: Clone,
Clones and appends all elements in a slice to the TiVec
.
See Vec::extend_from_slice
for more details.
Sourcepub fn extend_from_within<R>(&mut self, src: R)
pub fn extend_from_within<R>(&mut self, src: R)
Copies elements from src
range to the end of the vector.
See Vec::extend_from_within
for more details.
§Panics
Panics if the starting point is greater than the end point or if the end point is greater than the length of the vector.
Sourcepub fn dedup(&mut self)where
V: PartialEq,
pub fn dedup(&mut self)where
V: PartialEq,
Removes consecutive repeated elements in the vector according to the
PartialEq
trait implementation.
See Vec::dedup
for more details.
Sourcepub fn splice<R, I>(
&mut self,
range: R,
replace_with: I,
) -> Splice<'_, I::IntoIter> ⓘwhere
R: TiRangeBounds<K>,
I: IntoIterator<Item = V>,
pub fn splice<R, I>(
&mut self,
range: R,
replace_with: I,
) -> Splice<'_, I::IntoIter> ⓘwhere
R: TiRangeBounds<K>,
I: IntoIterator<Item = V>,
Creates a splicing iterator that replaces the specified range in the
vector with the given replace_with
iterator and yields the removed
items. replace_with
does not need to be the same length as
range
.
See Vec::splice
for more details.
Sourcepub fn into_iter_enumerated(self) -> TiEnumerated<IntoIter<V>, K, V>
pub fn into_iter_enumerated(self) -> TiEnumerated<IntoIter<V>, K, V>
Converts the vector into iterator over all key-value pairs
with K
used for iteration indices.
It acts like self.into_iter().enumerate()
,
but use K
instead of usize
for iteration indices.
§Example
#[derive(Eq, Debug, From, Into, PartialEq)]
pub struct Id(usize);
let vec: TiVec<Id, usize> = vec![1, 2, 4].into();
let mut iterator = vec.into_iter_enumerated();
assert_eq!(iterator.next(), Some((Id(0), 1)));
assert_eq!(iterator.next(), Some((Id(1), 2)));
assert_eq!(iterator.next(), Some((Id(2), 4)));
assert_eq!(iterator.next(), None);
Methods from Deref<Target = TiSlice<K, V>>§
Sourcepub fn len(&self) -> usize
pub fn len(&self) -> usize
Returns the number of elements in the slice.
See slice::len
for more details.
Sourcepub fn next_key(&self) -> K
pub fn next_key(&self) -> K
Returns the index of the next slice element to be appended
and at the same time number of elements in the slice of type K
.
§Example
#[derive(Eq, Debug, From, Into, PartialEq)]
pub struct Id(usize);
let slice: &TiSlice<Id, usize> = TiSlice::from_ref(&[1, 2, 4]);
assert_eq!(slice.next_key(), Id(3));
Sourcepub fn is_empty(&self) -> bool
pub fn is_empty(&self) -> bool
Returns true
if the slice has a length of 0.
See slice::is_empty
for more details.
Sourcepub fn keys(&self) -> TiSliceKeys<K>
pub fn keys(&self) -> TiSliceKeys<K>
Returns an iterator over all keys.
§Example
#[derive(Debug, Eq, From, Into, PartialEq)]
pub struct Id(usize);
let slice: &TiSlice<Id, usize> = TiSlice::from_ref(&[1, 2, 4]);
let mut iterator = slice.keys();
assert_eq!(iterator.next(), Some(Id(0)));
assert_eq!(iterator.next(), Some(Id(1)));
assert_eq!(iterator.next(), Some(Id(2)));
assert_eq!(iterator.next(), None);
Sourcepub fn first(&self) -> Option<&V>
pub fn first(&self) -> Option<&V>
Returns the first element of the slice, or None
if it is empty.
See slice::first
for more details.
Sourcepub fn first_mut(&mut self) -> Option<&mut V>
pub fn first_mut(&mut self) -> Option<&mut V>
Returns a mutable reference to the first element of the slice, or None
if it is empty.
See slice::first_mut
for more details.
Sourcepub fn first_key(&self) -> Option<K>
pub fn first_key(&self) -> Option<K>
Returns the first slice element index of type K
, or None
if the
slice is empty.
§Example
#[derive(Debug, Eq, From, Into, PartialEq)]
pub struct Id(usize);
let empty_slice: &TiSlice<Id, usize> = TiSlice::from_ref(&[]);
let slice: &TiSlice<Id, usize> = TiSlice::from_ref(&[1, 2, 4]);
assert_eq!(empty_slice.first_key(), None);
assert_eq!(slice.first_key(), Some(Id(0)));
Sourcepub fn first_key_value(&self) -> Option<(K, &V)>
pub fn first_key_value(&self) -> Option<(K, &V)>
Returns the first slice element index of type K
and the element
itself, or None
if the slice is empty.
See slice::first
for more details.
§Example
#[derive(Debug, Eq, From, Into, PartialEq)]
pub struct Id(usize);
let empty_slice: &TiSlice<Id, usize> = TiSlice::from_ref(&[]);
let slice: &TiSlice<Id, usize> = TiSlice::from_ref(&[1, 2, 4]);
assert_eq!(empty_slice.first_key_value(), None);
assert_eq!(slice.first_key_value(), Some((Id(0), &1)));
Sourcepub fn first_key_value_mut(&mut self) -> Option<(K, &mut V)>
pub fn first_key_value_mut(&mut self) -> Option<(K, &mut V)>
Returns the first slice element index of type K
and a mutable
reference to the element itself, or None
if the slice is empty.
See slice::first_mut
for more details.
§Example
#[derive(Debug, Eq, From, Into, PartialEq)]
pub struct Id(usize);
let empty_slice: &mut TiSlice<Id, usize> = TiSlice::from_mut(&mut []);
let mut array = [1, 2, 4];
let slice: &mut TiSlice<Id, usize> = TiSlice::from_mut(&mut array);
assert_eq!(empty_slice.first_key_value_mut(), None);
assert_eq!(slice.first_key_value_mut(), Some((Id(0), &mut 1)));
*slice.first_key_value_mut().unwrap().1 = 123;
assert_eq!(slice.raw, [123, 2, 4]);
Sourcepub fn split_first(&self) -> Option<(&V, &Self)>
pub fn split_first(&self) -> Option<(&V, &Self)>
Returns the first and all the rest of the elements of the slice, or
None
if it is empty.
See slice::split_first
for more details.
Sourcepub fn split_first_mut(&mut self) -> Option<(&mut V, &mut Self)>
pub fn split_first_mut(&mut self) -> Option<(&mut V, &mut Self)>
Returns the first and all the rest of the elements of the slice, or
None
if it is empty.
See slice::split_first_mut
for more details.
Sourcepub fn split_last(&self) -> Option<(&V, &Self)>
pub fn split_last(&self) -> Option<(&V, &Self)>
Returns the last and all the rest of the elements of the slice, or
None
if it is empty.
See slice::split_last
for more details.
Sourcepub fn split_last_mut(&mut self) -> Option<(&mut V, &mut Self)>
pub fn split_last_mut(&mut self) -> Option<(&mut V, &mut Self)>
Returns the last and all the rest of the elements of the slice, or
None
if it is empty.
See slice::split_last_mut
for more details.
Sourcepub fn last(&self) -> Option<&V>
pub fn last(&self) -> Option<&V>
Returns the last element of the slice of type K
, or None
if it is
empty.
See slice::last
for more details.
Sourcepub fn last_mut(&mut self) -> Option<&mut V>
pub fn last_mut(&mut self) -> Option<&mut V>
Returns a mutable reference to the last item in the slice.
See slice::last_mut
for more details.
Sourcepub fn last_key(&self) -> Option<K>
pub fn last_key(&self) -> Option<K>
Returns the last slice element index of type K
, or None
if the slice
is empty.
§Example
#[derive(Debug, Eq, From, Into, PartialEq)]
pub struct Id(usize);
let empty_slice: &TiSlice<Id, usize> = TiSlice::from_ref(&[]);
let slice: &TiSlice<Id, usize> = TiSlice::from_ref(&[1, 2, 4]);
assert_eq!(empty_slice.last_key(), None);
assert_eq!(slice.last_key(), Some(Id(2)));
Sourcepub fn last_key_value(&self) -> Option<(K, &V)>
pub fn last_key_value(&self) -> Option<(K, &V)>
Returns the last slice element index of type K
and the element itself,
or None
if the slice is empty.
See slice::last
for more details.
§Example
#[derive(Debug, Eq, From, Into, PartialEq)]
pub struct Id(usize);
let empty_slice: &TiSlice<Id, usize> = TiSlice::from_ref(&[]);
let slice: &TiSlice<Id, usize> = TiSlice::from_ref(&[1, 2, 4]);
assert_eq!(empty_slice.last_key_value(), None);
assert_eq!(slice.last_key_value(), Some((Id(2), &4)));
Sourcepub fn last_key_value_mut(&mut self) -> Option<(K, &mut V)>
pub fn last_key_value_mut(&mut self) -> Option<(K, &mut V)>
Returns the last slice element index of type K
and a mutable reference
to the element itself, or None
if the slice is empty.
See slice::last_mut
for more details.
§Example
#[derive(Debug, Eq, From, Into, PartialEq)]
pub struct Id(usize);
let empty_slice: &mut TiSlice<Id, usize> = TiSlice::from_mut(&mut []);
let mut array = [1, 2, 4];
let slice: &mut TiSlice<Id, usize> = TiSlice::from_mut(&mut array);
assert_eq!(empty_slice.last_key_value_mut(), None);
assert_eq!(slice.last_key_value_mut(), Some((Id(2), &mut 4)));
*slice.last_key_value_mut().unwrap().1 = 123;
assert_eq!(slice.raw, [1, 2, 123]);
Sourcepub fn get<I>(&self, index: I) -> Option<&I::Output>where
I: TiSliceIndex<K, V>,
pub fn get<I>(&self, index: I) -> Option<&I::Output>where
I: TiSliceIndex<K, V>,
Returns a reference to an element or subslice
depending on the type of index or None
if the index is out of bounds.
See slice::get
for more details.
Sourcepub fn get_mut<I>(&mut self, index: I) -> Option<&mut I::Output>where
I: TiSliceIndex<K, V>,
pub fn get_mut<I>(&mut self, index: I) -> Option<&mut I::Output>where
I: TiSliceIndex<K, V>,
Returns a mutable reference to an element or subslice
depending on the type of index or None
if the index is out of bounds.
See slice::get_mut
for more details.
Sourcepub unsafe fn get_unchecked<I>(&self, index: I) -> &I::Outputwhere
I: TiSliceIndex<K, V>,
pub unsafe fn get_unchecked<I>(&self, index: I) -> &I::Outputwhere
I: TiSliceIndex<K, V>,
Returns a reference to an element or subslice depending on the type of index, without doing bounds checking.
See slice::get_unchecked
for more details.
§Safety
Calling this method with an out-of-bounds index is
undefined behavior even if the resulting reference is not used.
For a safe alternative see get
.
Sourcepub unsafe fn get_unchecked_mut<I>(&mut self, index: I) -> &mut I::Outputwhere
I: TiSliceIndex<K, V>,
pub unsafe fn get_unchecked_mut<I>(&mut self, index: I) -> &mut I::Outputwhere
I: TiSliceIndex<K, V>,
Returns a mutable reference to an element or subslice depending on the type of index, without doing bounds checking.
See slice::get_unchecked_mut
for more details.
§Safety
Calling this method with an out-of-bounds index is
undefined behavior even if the resulting reference is not used.
For a safe alternative see get_mut
.
Sourcepub fn as_ptr(&self) -> *const V
pub fn as_ptr(&self) -> *const V
Returns a raw pointer to the slice’s buffer.
See slice::as_ptr
for more details.
Sourcepub fn as_mut_ptr(&mut self) -> *mut V
pub fn as_mut_ptr(&mut self) -> *mut V
Returns an unsafe mutable reference to the slice’s buffer.
See slice::as_mut_ptr
for more details.
Sourcepub fn as_ptr_range(&self) -> Range<*const V>
pub fn as_ptr_range(&self) -> Range<*const V>
Returns the two raw pointers spanning the slice.
See slice::as_ptr_range
for more details.
Sourcepub fn as_mut_ptr_range(&mut self) -> Range<*mut V>
pub fn as_mut_ptr_range(&mut self) -> Range<*mut V>
Returns the two unsafe mutable pointers spanning the slice.
See slice::as_mut_ptr_range
for more details.
Sourcepub fn swap(&mut self, a: K, b: K)
pub fn swap(&mut self, a: K, b: K)
Swaps two elements in the slice.
See slice::swap
for more details.
Sourcepub fn reverse(&mut self)
pub fn reverse(&mut self)
Reverses the order of elements in the slice, in place.
See slice::reverse
for more details.
Sourcepub fn iter(&self) -> Iter<'_, V>
pub fn iter(&self) -> Iter<'_, V>
Returns an iterator over the slice.
See slice::iter
for more details.
Sourcepub fn iter_enumerated(&self) -> TiEnumerated<Iter<'_, V>, K, &V>
pub fn iter_enumerated(&self) -> TiEnumerated<Iter<'_, V>, K, &V>
Returns an iterator over all key-value pairs.
It acts like self.iter().enumerate()
,
but use K
instead of usize
for iteration indices.
See slice::iter
for more details.
§Example
#[derive(Debug, Eq, From, Into, PartialEq)]
pub struct Id(usize);
let slice: &TiSlice<Id, usize> = TiSlice::from_ref(&[1, 2, 4]);
let mut iterator = slice.iter_enumerated();
assert_eq!(iterator.next(), Some((Id(0), &1)));
assert_eq!(iterator.next(), Some((Id(1), &2)));
assert_eq!(iterator.next(), Some((Id(2), &4)));
assert_eq!(iterator.next(), None);
Sourcepub fn iter_mut(&mut self) -> IterMut<'_, V>
pub fn iter_mut(&mut self) -> IterMut<'_, V>
Returns an iterator that allows modifying each value.
See slice::iter_mut
for more details.
Sourcepub fn iter_mut_enumerated(&mut self) -> TiEnumerated<IterMut<'_, V>, K, &mut V>
pub fn iter_mut_enumerated(&mut self) -> TiEnumerated<IterMut<'_, V>, K, &mut V>
Returns an iterator over all key-value pairs, with mutable references to the values.
It acts like self.iter_mut().enumerate()
,
but use K
instead of usize
for iteration indices.
§Example
#[derive(Debug, Eq, From, Into, PartialEq)]
pub struct Id(usize);
let mut array = [1, 2, 4];
let slice: &mut TiSlice<Id, usize> = TiSlice::from_mut(&mut array);
for (key, value) in slice.iter_mut_enumerated() {
*value += key.0;
}
assert_eq!(array, [1, 3, 6]);
Sourcepub fn position<P>(&self, predicate: P) -> Option<K>
pub fn position<P>(&self, predicate: P) -> Option<K>
Searches for an element in an iterator, returning its index of type K
.
It acts like self.iter().position(...)
,
but instead of usize
it returns index of type K
.
See slice::iter
and Iterator::position
for more details.
§Example
#[derive(Debug, Eq, From, Into, PartialEq)]
pub struct Id(usize);
let slice: &TiSlice<Id, usize> = TiSlice::from_ref(&[1, 2, 4, 2, 1]);
assert_eq!(slice.position(|&value| value == 1), Some(Id(0)));
assert_eq!(slice.position(|&value| value == 2), Some(Id(1)));
assert_eq!(slice.position(|&value| value == 3), None);
assert_eq!(slice.position(|&value| value == 4), Some(Id(2)));
Sourcepub fn rposition<P>(&self, predicate: P) -> Option<K>
pub fn rposition<P>(&self, predicate: P) -> Option<K>
Searches for an element in an iterator from the right, returning its
index of type K
.
It acts like self.iter().rposition(...)
,
but instead of usize
it returns index of type K
.
See slice::iter
and Iterator::rposition
for more details.
§Example
#[derive(Debug, Eq, From, Into, PartialEq)]
pub struct Id(usize);
let slice: &TiSlice<Id, usize> = TiSlice::from_ref(&[1, 2, 4, 2, 1]);
assert_eq!(slice.rposition(|&value| value == 1), Some(Id(4)));
assert_eq!(slice.rposition(|&value| value == 2), Some(Id(3)));
assert_eq!(slice.rposition(|&value| value == 3), None);
assert_eq!(slice.rposition(|&value| value == 4), Some(Id(2)));
Sourcepub fn windows(&self, size: usize) -> TiSliceRefMap<Windows<'_, V>, K, V>
pub fn windows(&self, size: usize) -> TiSliceRefMap<Windows<'_, V>, K, V>
Returns an iterator over all contiguous windows of length
size
. The windows overlap. If the slice is shorter than
size
, the iterator returns no values.
See slice::windows
for more details.
Sourcepub fn chunks(&self, chunk_size: usize) -> TiSliceRefMap<Chunks<'_, V>, K, V>
pub fn chunks(&self, chunk_size: usize) -> TiSliceRefMap<Chunks<'_, V>, K, V>
Returns an iterator over chunk_size
elements of the slice at a time,
starting at the beginning of the slice.
See slice::chunks
for more details.
Sourcepub fn chunks_mut(
&mut self,
chunk_size: usize,
) -> TiSliceMutMap<ChunksMut<'_, V>, K, V>
pub fn chunks_mut( &mut self, chunk_size: usize, ) -> TiSliceMutMap<ChunksMut<'_, V>, K, V>
Returns an iterator over chunk_size
elements of the slice at a time,
starting at the beginning of the slice.
See slice::chunks_mut
for more details.
Sourcepub fn chunks_exact(
&self,
chunk_size: usize,
) -> TiSliceRefMap<ChunksExact<'_, V>, K, V>
pub fn chunks_exact( &self, chunk_size: usize, ) -> TiSliceRefMap<ChunksExact<'_, V>, K, V>
Returns an iterator over chunk_size
elements of the slice at a time,
starting at the beginning of the slice.
See slice::chunks_exact
for more details.
Sourcepub fn chunks_exact_mut(
&mut self,
chunk_size: usize,
) -> TiSliceMutMap<ChunksExactMut<'_, V>, K, V>
pub fn chunks_exact_mut( &mut self, chunk_size: usize, ) -> TiSliceMutMap<ChunksExactMut<'_, V>, K, V>
Returns an iterator over chunk_size
elements of the slice at a time,
starting at the beginning of the slice.
See slice::chunks_exact_mut
for more details.
Sourcepub fn rchunks(&self, chunk_size: usize) -> TiSliceRefMap<RChunks<'_, V>, K, V>
pub fn rchunks(&self, chunk_size: usize) -> TiSliceRefMap<RChunks<'_, V>, K, V>
Returns an iterator over chunk_size
elements of the slice at a time,
starting at the end of the slice.
See slice::rchunks
for more details.
Sourcepub fn rchunks_mut(
&mut self,
chunk_size: usize,
) -> TiSliceMutMap<RChunksMut<'_, V>, K, V>
pub fn rchunks_mut( &mut self, chunk_size: usize, ) -> TiSliceMutMap<RChunksMut<'_, V>, K, V>
Returns an iterator over chunk_size
elements of the slice at a time,
starting at the end of the slice.
See slice::rchunks_mut
for more details.
Sourcepub fn rchunks_exact(
&self,
chunk_size: usize,
) -> TiSliceRefMap<RChunksExact<'_, V>, K, V>
pub fn rchunks_exact( &self, chunk_size: usize, ) -> TiSliceRefMap<RChunksExact<'_, V>, K, V>
Returns an iterator over chunk_size
elements of the slice at a time,
starting at the end of the slice.
See slice::rchunks_exact
for more details.
Sourcepub fn rchunks_exact_mut(
&mut self,
chunk_size: usize,
) -> TiSliceMutMap<RChunksExactMut<'_, V>, K, V>
pub fn rchunks_exact_mut( &mut self, chunk_size: usize, ) -> TiSliceMutMap<RChunksExactMut<'_, V>, K, V>
Returns an iterator over chunk_size
elements of the slice at a time,
starting at the end of the slice.
See slice::rchunks_exact_mut
for more details.
Sourcepub fn chunk_by<F>(&self, pred: F) -> TiSliceRefMap<ChunkBy<'_, V, F>, K, V>
pub fn chunk_by<F>(&self, pred: F) -> TiSliceRefMap<ChunkBy<'_, V, F>, K, V>
Returns an iterator over the slice producing non-overlapping runs of elements using the predicate to separate them.
See slice::chunk_by
for more details.
Sourcepub fn chunk_by_mut<F>(
&mut self,
pred: F,
) -> TiSliceMutMap<ChunkByMut<'_, V, F>, K, V>
pub fn chunk_by_mut<F>( &mut self, pred: F, ) -> TiSliceMutMap<ChunkByMut<'_, V, F>, K, V>
Returns an iterator over the slice producing non-overlapping mutable runs of elements using the predicate to separate them.
See slice::chunk_by_mut
for more details.
Sourcepub fn split_at(&self, mid: K) -> (&Self, &Self)
pub fn split_at(&self, mid: K) -> (&Self, &Self)
Divides one slice into two at an index.
See slice::split_at
for more details.
Sourcepub fn split_at_mut(&mut self, mid: K) -> (&mut Self, &mut Self)
pub fn split_at_mut(&mut self, mid: K) -> (&mut Self, &mut Self)
Divides one mutable slice into two at an index.
See slice::split_at_mut
for more details.
Sourcepub unsafe fn split_at_unchecked(&self, mid: K) -> (&Self, &Self)
pub unsafe fn split_at_unchecked(&self, mid: K) -> (&Self, &Self)
Divides one slice into two at an index, without doing bounds checking.
See slice::split_at_unchecked
for more details.
§Safety
Calling this method with an out-of-bounds index is
undefined behavior even if the resulting reference is not used. The
caller has to ensure that 0 <= mid <= self.len()
.
Sourcepub unsafe fn split_at_mut_unchecked(
&mut self,
mid: K,
) -> (&mut Self, &mut Self)
pub unsafe fn split_at_mut_unchecked( &mut self, mid: K, ) -> (&mut Self, &mut Self)
Divides one mutable slice into two at an index, without doing bounds checking.
See slice::split_at_mut_unchecked
for more details.
§Safety
Calling this method with an out-of-bounds index is
undefined behavior even if the resulting reference is not used. The
caller has to ensure that 0 <= mid <= self.len()
.
Sourcepub fn split_at_checked(&self, mid: K) -> Option<(&Self, &Self)>
pub fn split_at_checked(&self, mid: K) -> Option<(&Self, &Self)>
Divides one slice into two at an index, returning None
if the slice is
too short.
See slice::split_at_checked
for more details.
Sourcepub fn split_at_mut_checked(&mut self, mid: K) -> Option<(&mut Self, &mut Self)>
pub fn split_at_mut_checked(&mut self, mid: K) -> Option<(&mut Self, &mut Self)>
Divides one mutable slice into two at an index, returning None
if the
slice is too short.
See slice::split_at_mut_checked
for more details.
Sourcepub fn split<F>(&self, pred: F) -> TiSliceRefMap<Split<'_, V, F>, K, V>
pub fn split<F>(&self, pred: F) -> TiSliceRefMap<Split<'_, V, F>, K, V>
Returns an iterator over subslices separated by elements that match
pred
. The matched element is not contained in the subslices.
See slice::split
for more details.
Sourcepub fn split_mut<F>(
&mut self,
pred: F,
) -> TiSliceMutMap<SplitMut<'_, V, F>, K, V>
pub fn split_mut<F>( &mut self, pred: F, ) -> TiSliceMutMap<SplitMut<'_, V, F>, K, V>
Returns an iterator over mutable subslices separated by elements that
match pred
. The matched element is not contained in the subslices.
See slice::split_mut
for more details.
Sourcepub fn split_inclusive<F>(
&self,
pred: F,
) -> TiSliceRefMap<SplitInclusive<'_, V, F>, K, V>
pub fn split_inclusive<F>( &self, pred: F, ) -> TiSliceRefMap<SplitInclusive<'_, V, F>, K, V>
Returns an iterator over subslices separated by elements that match
pred
. The matched element is contained in the end of the previous
subslice as a terminator.
See slice::split_inclusive
for more details.
Sourcepub fn split_inclusive_mut<F>(
&mut self,
pred: F,
) -> TiSliceMutMap<SplitInclusiveMut<'_, V, F>, K, V>
pub fn split_inclusive_mut<F>( &mut self, pred: F, ) -> TiSliceMutMap<SplitInclusiveMut<'_, V, F>, K, V>
Returns an iterator over mutable subslices separated by elements that
match pred
. The matched element is contained in the previous
subslice as a terminator.
See slice::split_inclusive_mut
for more details.
Sourcepub fn rsplit<F>(&self, pred: F) -> TiSliceRefMap<RSplit<'_, V, F>, K, V>
pub fn rsplit<F>(&self, pred: F) -> TiSliceRefMap<RSplit<'_, V, F>, K, V>
Returns an iterator over subslices separated by elements that match
pred
, starting at the end of the slice and working backwards.
The matched element is not contained in the subslices.
See slice::rsplit
for more details.
Sourcepub fn rsplit_mut<F>(
&mut self,
pred: F,
) -> TiSliceMutMap<RSplitMut<'_, V, F>, K, V>
pub fn rsplit_mut<F>( &mut self, pred: F, ) -> TiSliceMutMap<RSplitMut<'_, V, F>, K, V>
Returns an iterator over mutable subslices separated by elements that
match pred
, starting at the end of the slice and working
backwards. The matched element is not contained in the subslices.
See slice::rsplit_mut
for more details.
Sourcepub fn splitn<F>(
&self,
n: usize,
pred: F,
) -> TiSliceRefMap<SplitN<'_, V, F>, K, V>
pub fn splitn<F>( &self, n: usize, pred: F, ) -> TiSliceRefMap<SplitN<'_, V, F>, K, V>
Returns an iterator over subslices separated by elements that match
pred
, limited to returning at most n
items. The matched element is
not contained in the subslices.
See slice::splitn
for more details.
Sourcepub fn splitn_mut<F>(
&mut self,
n: usize,
pred: F,
) -> TiSliceMutMap<SplitNMut<'_, V, F>, K, V>
pub fn splitn_mut<F>( &mut self, n: usize, pred: F, ) -> TiSliceMutMap<SplitNMut<'_, V, F>, K, V>
Returns an iterator over subslices separated by elements that match
pred
, limited to returning at most n
items. The matched element is
not contained in the subslices.
See slice::splitn_mut
for more details.
Sourcepub fn rsplitn<F>(
&self,
n: usize,
pred: F,
) -> TiSliceRefMap<RSplitN<'_, V, F>, K, V>
pub fn rsplitn<F>( &self, n: usize, pred: F, ) -> TiSliceRefMap<RSplitN<'_, V, F>, K, V>
Returns an iterator over subslices separated by elements that match
pred
limited to returning at most n
items. This starts at the end of
the slice and works backwards. The matched element is not contained in
the subslices.
See slice::rsplitn
for more details.
Sourcepub fn rsplitn_mut<F>(
&mut self,
n: usize,
pred: F,
) -> TiSliceMutMap<RSplitNMut<'_, V, F>, K, V>
pub fn rsplitn_mut<F>( &mut self, n: usize, pred: F, ) -> TiSliceMutMap<RSplitNMut<'_, V, F>, K, V>
Returns an iterator over subslices separated by elements that match
pred
limited to returning at most n
items. This starts at the end of
the slice and works backwards. The matched element is not contained in
the subslices.
See slice::rsplitn_mut
for more details.
Sourcepub fn contains(&self, x: &V) -> boolwhere
V: PartialEq,
pub fn contains(&self, x: &V) -> boolwhere
V: PartialEq,
Returns true
if the slice contains an element with the given value.
See slice::contains
for more details.
Sourcepub fn starts_with(&self, needle: &Self) -> boolwhere
V: PartialEq,
pub fn starts_with(&self, needle: &Self) -> boolwhere
V: PartialEq,
Returns true
if needle
is a prefix of the slice.
See slice::starts_with
for more details.
Sourcepub fn ends_with(&self, needle: &Self) -> boolwhere
V: PartialEq,
pub fn ends_with(&self, needle: &Self) -> boolwhere
V: PartialEq,
Returns true
if needle
is a suffix of the slice.
See slice::ends_with
for more details.
Sourcepub fn binary_search(&self, x: &V) -> Result<K, K>
pub fn binary_search(&self, x: &V) -> Result<K, K>
Binary searches this sorted slice for a given element.
See slice::binary_search
for more details.
Sourcepub fn binary_search_by<'a, F>(&'a self, f: F) -> Result<K, K>
pub fn binary_search_by<'a, F>(&'a self, f: F) -> Result<K, K>
Binary searches this sorted slice with a comparator function.
See slice::binary_search_by
for more details.
Sourcepub fn binary_search_by_key<'a, B, F>(&'a self, b: &B, f: F) -> Result<K, K>
pub fn binary_search_by_key<'a, B, F>(&'a self, b: &B, f: F) -> Result<K, K>
Binary searches this sorted slice with a key extraction function.
See slice::binary_search_by_key
for more details.
Sourcepub fn sort_unstable(&mut self)where
V: Ord,
pub fn sort_unstable(&mut self)where
V: Ord,
Sorts the slice, but may not preserve the order of equal elements.
See slice::sort_unstable
for more details.
Sourcepub fn sort_unstable_by<F>(&mut self, compare: F)
pub fn sort_unstable_by<F>(&mut self, compare: F)
Sorts the slice with a comparator function, but may not preserve the order of equal elements.
See slice::sort_unstable_by
for more details.
Sourcepub fn sort_unstable_by_key<K2, F>(&mut self, f: F)
pub fn sort_unstable_by_key<K2, F>(&mut self, f: F)
Sorts the slice with a key extraction function, but may not preserve the order of equal elements.
See slice::sort_unstable_by_key
for more details.
Sourcepub fn select_nth_unstable(
&mut self,
index: K,
) -> (&mut Self, &mut V, &mut Self)
pub fn select_nth_unstable( &mut self, index: K, ) -> (&mut Self, &mut V, &mut Self)
Reorder the slice such that the element at index
after the reordering
is at its final sorted position.
See slice::select_nth_unstable
for more details.
§Panics
Panics when index >= len()
, meaning it always panics on empty slices.
May panic if the implementation of Ord
for T
does not implement a
[total order].
Sourcepub fn select_nth_unstable_by<F>(
&mut self,
index: K,
compare: F,
) -> (&mut Self, &mut V, &mut Self)
pub fn select_nth_unstable_by<F>( &mut self, index: K, compare: F, ) -> (&mut Self, &mut V, &mut Self)
Reorder the slice with a comparator function such that the element at
index
after the reordering is at its final sorted position.
See slice::select_nth_unstable_by
for more details.
§Panics
Panics when index >= len()
, meaning it always panics on empty slices.
May panic if compare
does not implement a [total order].
Sourcepub fn select_nth_unstable_by_key<Key, F>(
&mut self,
index: K,
f: F,
) -> (&mut Self, &mut V, &mut Self)
pub fn select_nth_unstable_by_key<Key, F>( &mut self, index: K, f: F, ) -> (&mut Self, &mut V, &mut Self)
Reorder the slice with a key extraction function such that the element
at index
after the reordering is at its final sorted position.
See slice::select_nth_unstable_by_key
for more details.
§Panics
Panics when index >= len()
, meaning it always panics on empty slices.
May panic if K: Ord
does not implement a total order.
Sourcepub fn rotate_left(&mut self, mid: K)
pub fn rotate_left(&mut self, mid: K)
Rotates the slice in-place such that the first mid
elements of the
slice move to the end while the last self.next_key() - mid
elements
move to the front. After calling rotate_left
, the element
previously at index mid
will become the first element in the
slice.
See slice::rotate_left
for more details.
Sourcepub fn rotate_right(&mut self, k: K)
pub fn rotate_right(&mut self, k: K)
Rotates the slice in-place such that the first self.next_key() - k
elements of the slice move to the end while the last k
elements move
to the front. After calling rotate_right
, the element previously at
index self.next_key() - k
will become the first element in the slice.
See slice::rotate_right
for more details.
Sourcepub fn fill(&mut self, value: V)where
V: Clone,
pub fn fill(&mut self, value: V)where
V: Clone,
Fills self
with elements by cloning value
.
See slice::fill
for more details.
Sourcepub fn fill_with<F>(&mut self, f: F)where
F: FnMut() -> V,
pub fn fill_with<F>(&mut self, f: F)where
F: FnMut() -> V,
Fills self
with elements returned by calling a closure repeatedly.
See slice::fill_with
for more details.
Sourcepub fn clone_from_slice(&mut self, src: &Self)where
V: Clone,
pub fn clone_from_slice(&mut self, src: &Self)where
V: Clone,
Copies the elements from src
into self
.
See slice::clone_from_slice
for more details.
Sourcepub fn copy_from_slice(&mut self, src: &Self)where
V: Copy,
pub fn copy_from_slice(&mut self, src: &Self)where
V: Copy,
Copies all elements from src
into self
, using a memcpy.
See slice::copy_from_slice
for more details.
Sourcepub fn copy_within<R>(&mut self, src: R, dest: K)
pub fn copy_within<R>(&mut self, src: R, dest: K)
Copies elements from one part of the slice to another part of itself, using a memmove.
See slice::copy_within
for more details.
Sourcepub fn swap_with_slice(&mut self, other: &mut Self)
pub fn swap_with_slice(&mut self, other: &mut Self)
Swaps all elements in self
with those in other
.
See slice::swap_with_slice
for more details.
Sourcepub unsafe fn align_to<U>(&self) -> (&Self, &TiSlice<K, U>, &Self)
pub unsafe fn align_to<U>(&self) -> (&Self, &TiSlice<K, U>, &Self)
Transmute the slice to a slice of another type, ensuring alignment of the types is maintained.
See slice::align_to
for more details.
§Safety
This method is essentially a transmute
with respect to the elements in
the returned middle slice, so all the usual caveats pertaining to
transmute::<T, U>
also apply here.
Sourcepub unsafe fn align_to_mut<U>(
&mut self,
) -> (&mut Self, &mut TiSlice<K, U>, &mut Self)
pub unsafe fn align_to_mut<U>( &mut self, ) -> (&mut Self, &mut TiSlice<K, U>, &mut Self)
Transmute the slice to a slice of another type, ensuring alignment of the types is maintained.
See slice::align_to_mut
for more details.
§Safety
This method is essentially a transmute
with respect to the elements in
the returned middle slice, so all the usual caveats pertaining to
transmute::<T, U>
also apply here.
Sourcepub fn is_sorted(&self) -> boolwhere
V: PartialOrd,
pub fn is_sorted(&self) -> boolwhere
V: PartialOrd,
Checks if the elements of this slice are sorted.
See slice::is_sorted
for more details.
Sourcepub fn is_sorted_by<'a, F>(&'a self, compare: F) -> bool
pub fn is_sorted_by<'a, F>(&'a self, compare: F) -> bool
Checks if the elements of this slice are sorted using the given comparator function.
See slice::is_sorted_by
for more details.
Sourcepub fn is_sorted_by_key<'a, F, T>(&'a self, f: F) -> bool
pub fn is_sorted_by_key<'a, F, T>(&'a self, f: F) -> bool
Checks if the elements of this slice are sorted using the given key extraction function.
See slice::is_sorted_by_key
for more details.
Sourcepub fn partition_point<P>(&self, pred: P) -> K
pub fn partition_point<P>(&self, pred: P) -> K
Returns the index of the partition point according to the given predicate (the index of the first element of the second partition).
See slice::partition_point
for more details.
Sourcepub fn sort(&mut self)where
V: Ord,
pub fn sort(&mut self)where
V: Ord,
Sorts the slice.
See slice::sort
for more details.
Sourcepub fn sort_by<F>(&mut self, compare: F)
pub fn sort_by<F>(&mut self, compare: F)
Sorts the slice with a comparator function.
See slice::sort_by
for more details.
Sourcepub fn sort_by_key<K2, F>(&mut self, f: F)
pub fn sort_by_key<K2, F>(&mut self, f: F)
Sorts the slice with a key extraction function.
See slice::sort_by_key
for more details.
Sourcepub fn sort_by_cached_key<K2, F>(&mut self, f: F)
pub fn sort_by_cached_key<K2, F>(&mut self, f: F)
Sorts the slice with a key extraction function.
See slice::sort_by_cached_key
for more details.
Sourcepub fn to_vec(&self) -> TiVec<K, V>where
V: Clone,
pub fn to_vec(&self) -> TiVec<K, V>where
V: Clone,
Copies self
into a new TiVec
.
See slice::to_vec
for more details.
Sourcepub fn repeat(&self, n: usize) -> TiVec<K, V>where
V: Copy,
pub fn repeat(&self, n: usize) -> TiVec<K, V>where
V: Copy,
Creates a vector by repeating a slice n
times.
See slice::repeat
for more details.
Sourcepub fn concat<Item: ?Sized>(&self) -> <Self as Concat<Item>>::Outputwhere
Self: Concat<Item>,
pub fn concat<Item: ?Sized>(&self) -> <Self as Concat<Item>>::Outputwhere
Self: Concat<Item>,
Flattens a slice of T
into a single value Self::Output
.
See slice::concat
for more details.
Sourcepub fn join<Separator>(
&self,
sep: Separator,
) -> <Self as Join<Separator>>::Outputwhere
Self: Join<Separator>,
pub fn join<Separator>(
&self,
sep: Separator,
) -> <Self as Join<Separator>>::Outputwhere
Self: Join<Separator>,
Flattens a slice of T
into a single value Self::Output
, placing a
given separator between each.
See slice::join
for more details.
Trait Implementations§
Source§impl<K, V> BorrowMut<TiSlice<K, V>> for TiVec<K, V>
impl<K, V> BorrowMut<TiSlice<K, V>> for TiVec<K, V>
Source§fn borrow_mut(&mut self) -> &mut TiSlice<K, V>
fn borrow_mut(&mut self) -> &mut TiSlice<K, V>
Source§impl<'a, K, V: 'a + Copy> Extend<&'a V> for TiVec<K, V>
impl<'a, K, V: 'a + Copy> Extend<&'a V> for TiVec<K, V>
Source§fn extend<I: IntoIterator<Item = &'a V>>(&mut self, iter: I)
fn extend<I: IntoIterator<Item = &'a V>>(&mut self, iter: I)
Source§fn extend_one(&mut self, item: A)
fn extend_one(&mut self, item: A)
extend_one
)Source§fn extend_reserve(&mut self, additional: usize)
fn extend_reserve(&mut self, additional: usize)
extend_one
)Source§impl<K, V> Extend<V> for TiVec<K, V>
impl<K, V> Extend<V> for TiVec<K, V>
Source§fn extend<I: IntoIterator<Item = V>>(&mut self, iter: I)
fn extend<I: IntoIterator<Item = V>>(&mut self, iter: I)
Source§fn extend_one(&mut self, item: A)
fn extend_one(&mut self, item: A)
extend_one
)Source§fn extend_reserve(&mut self, additional: usize)
fn extend_reserve(&mut self, additional: usize)
extend_one
)Source§impl<K, V> FromIterator<V> for TiVec<K, V>
impl<K, V> FromIterator<V> for TiVec<K, V>
Source§fn from_iter<I: IntoIterator<Item = V>>(iter: I) -> Self
fn from_iter<I: IntoIterator<Item = V>>(iter: I) -> Self
Source§impl<I, K, V> Index<I> for TiVec<K, V>where
I: TiSliceIndex<K, V>,
impl<I, K, V> Index<I> for TiVec<K, V>where
I: TiSliceIndex<K, V>,
Source§impl<I, K, V> IndexMut<I> for TiVec<K, V>where
I: TiSliceIndex<K, V>,
impl<I, K, V> IndexMut<I> for TiVec<K, V>where
I: TiSliceIndex<K, V>,
Source§impl<'a, K, V> IntoIterator for &'a TiVec<K, V>
impl<'a, K, V> IntoIterator for &'a TiVec<K, V>
Source§impl<'a, K, V> IntoIterator for &'a mut TiVec<K, V>
impl<'a, K, V> IntoIterator for &'a mut TiVec<K, V>
Source§impl<K, V> IntoIterator for TiVec<K, V>
impl<K, V> IntoIterator for TiVec<K, V>
Source§impl<K, V> Ord for TiVec<K, V>where
V: Ord,
impl<K, V> Ord for TiVec<K, V>where
V: Ord,
Source§impl<K, V> PartialOrd for TiVec<K, V>where
V: PartialOrd<V>,
impl<K, V> PartialOrd for TiVec<K, V>where
V: PartialOrd<V>,
Source§impl<K> Write for TiVec<K, u8>
Available on crate feature std
only.Write is implemented for Vec<u8>
by appending to the vector.
The vector will grow as needed.
impl<K> Write for TiVec<K, u8>
std
only.Write is implemented for Vec<u8>
by appending to the vector.
The vector will grow as needed.
Source§fn write(&mut self, buf: &[u8]) -> IoResult<usize>
fn write(&mut self, buf: &[u8]) -> IoResult<usize>
Source§fn write_all(&mut self, buf: &[u8]) -> IoResult<()>
fn write_all(&mut self, buf: &[u8]) -> IoResult<()>
Source§fn flush(&mut self) -> IoResult<()>
fn flush(&mut self) -> IoResult<()>
Source§fn is_write_vectored(&self) -> bool
fn is_write_vectored(&self) -> bool
can_vector
)Source§fn write_all_vectored(&mut self, bufs: &mut [IoSlice<'_>]) -> Result<(), Error>
fn write_all_vectored(&mut self, bufs: &mut [IoSlice<'_>]) -> Result<(), Error>
write_all_vectored
)impl<K, V> Eq for TiVec<K, V>where
V: Eq,
Auto Trait Implementations§
impl<K, V> Freeze for TiVec<K, V>
impl<K, V> RefUnwindSafe for TiVec<K, V>where
V: RefUnwindSafe,
impl<K, V> Send for TiVec<K, V>where
V: Send,
impl<K, V> Sync for TiVec<K, V>where
V: Sync,
impl<K, V> Unpin for TiVec<K, V>where
V: Unpin,
impl<K, V> UnwindSafe for TiVec<K, V>where
V: UnwindSafe,
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
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Layout§
Note: Most layout information is completely unstable and may even differ between compilations. The only exception is types with certain repr(...)
attributes. Please see the Rust Reference's “Type Layout” chapter for details on type layout guarantees.
Size: 24 bytes