Type Alias TypeWalkerStack

Source
type TypeWalkerStack<'tcx> = SmallVec<[GenericArg<'tcx>; 8]>;

Aliased Type§

struct TypeWalkerStack<'tcx> { /* private fields */ }

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: 72 bytes

Implementations

Source§

impl<A> SmallVec<A>
where A: Array, <A as Array>::Item: Copy,

Source

pub fn from_slice(slice: &[<A as Array>::Item]) -> SmallVec<A>

Copy the elements from a slice into a new SmallVec.

For slices of Copy types, this is more efficient than SmallVec::from(slice).

Source

pub fn insert_from_slice(&mut self, index: usize, slice: &[<A as Array>::Item])

Copy elements from a slice into the vector at position index, shifting any following elements toward the back.

For slices of Copy types, this is more efficient than insert.

Source

pub fn extend_from_slice(&mut self, slice: &[<A as Array>::Item])

Copy elements from a slice and append them to the vector.

For slices of Copy types, this is more efficient than extend.

Source§

impl<A> SmallVec<A>
where A: Array, <A as Array>::Item: Clone,

Source

pub fn resize(&mut self, len: usize, value: <A as Array>::Item)

Resizes the vector so that its length is equal to len.

If len is less than the current length, the vector simply truncated.

If len is greater than the current length, value is appended to the vector until its length equals len.

Source

pub fn from_elem(elem: <A as Array>::Item, n: usize) -> SmallVec<A>

Creates a SmallVec with n copies of elem.

use smallvec::SmallVec;

let v = SmallVec::<[char; 128]>::from_elem('d', 2);
assert_eq!(v, SmallVec::from_buf(['d', 'd']));
Source§

impl<A> SmallVec<A>
where A: Array,

Source

pub fn new() -> SmallVec<A>

Construct an empty vector

Source

pub fn with_capacity(n: usize) -> SmallVec<A>

Construct an empty vector with enough capacity pre-allocated to store at least n elements.

Will create a heap allocation only if n is larger than the inline capacity.


let v: SmallVec<[u8; 3]> = SmallVec::with_capacity(100);

assert!(v.is_empty());
assert!(v.capacity() >= 100);
Source

pub fn from_vec(vec: Vec<<A as Array>::Item>) -> SmallVec<A>

Construct a new SmallVec from a Vec<A::Item>.

Elements will be copied to the inline buffer if vec.capacity() <= Self::inline_capacity().

use smallvec::SmallVec;

let vec = vec![1, 2, 3, 4, 5];
let small_vec: SmallVec<[_; 3]> = SmallVec::from_vec(vec);

assert_eq!(&*small_vec, &[1, 2, 3, 4, 5]);
Source

pub fn from_buf(buf: A) -> SmallVec<A>

Constructs a new SmallVec on the stack from an A without copying elements.

use smallvec::SmallVec;

let buf = [1, 2, 3, 4, 5];
let small_vec: SmallVec<_> = SmallVec::from_buf(buf);

assert_eq!(&*small_vec, &[1, 2, 3, 4, 5]);
Source

pub fn from_buf_and_len(buf: A, len: usize) -> SmallVec<A>

Constructs a new SmallVec on the stack from an A without copying elements. Also sets the length, which must be less or equal to the size of buf.

use smallvec::SmallVec;

let buf = [1, 2, 3, 4, 5, 0, 0, 0];
let small_vec: SmallVec<_> = SmallVec::from_buf_and_len(buf, 5);

assert_eq!(&*small_vec, &[1, 2, 3, 4, 5]);
Source

pub unsafe fn from_buf_and_len_unchecked( buf: MaybeUninit<A>, len: usize, ) -> SmallVec<A>

Constructs a new SmallVec on the stack from an A without copying elements. Also sets the length. The user is responsible for ensuring that len <= A::size().

use smallvec::SmallVec;
use std::mem::MaybeUninit;

let buf = [1, 2, 3, 4, 5, 0, 0, 0];
let small_vec: SmallVec<_> = unsafe {
    SmallVec::from_buf_and_len_unchecked(MaybeUninit::new(buf), 5)
};

assert_eq!(&*small_vec, &[1, 2, 3, 4, 5]);
Source

pub unsafe fn set_len(&mut self, new_len: usize)

Sets the length of a vector.

This will explicitly set the size of the vector, without actually modifying its buffers, so it is up to the caller to ensure that the vector is actually the specified size.

Source

pub fn inline_size(&self) -> usize

The maximum number of elements this vector can hold inline

Source

pub fn len(&self) -> usize

The number of elements stored in the vector

Source

pub fn is_empty(&self) -> bool

Returns true if the vector is empty

Source

pub fn capacity(&self) -> usize

The number of items the vector can hold without reallocating

Source

pub fn spilled(&self) -> bool

Returns true if the data has spilled into a separate heap-allocated buffer.

Source

pub fn drain<R>(&mut self, range: R) -> Drain<'_, A>
where R: RangeBounds<usize>,

Creates a draining iterator that removes the specified range in the vector and yields the removed items.

Note 1: The element range is removed even if the iterator is only partially consumed or not consumed at all.

Note 2: It is unspecified how many elements are removed from the vector if the Drain value is leaked.

§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.

Source

pub fn push(&mut self, value: <A as Array>::Item)

Append an item to the vector.

Source

pub fn pop(&mut self) -> Option<<A as Array>::Item>

Remove an item from the end of the vector and return it, or None if empty.

Source

pub fn append<B>(&mut self, other: &mut SmallVec<B>)
where B: Array<Item = <A as Array>::Item>,

Moves all the elements of other into self, leaving other empty.

§Example
let mut v0: SmallVec<[u8; 16]> = smallvec![1, 2, 3];
let mut v1: SmallVec<[u8; 32]> = smallvec![4, 5, 6];
v0.append(&mut v1);
assert_eq!(*v0, [1, 2, 3, 4, 5, 6]);
assert_eq!(*v1, []);
Source

pub fn grow(&mut self, new_cap: usize)

Re-allocate to set the capacity to max(new_cap, inline_size()).

Panics if new_cap is less than the vector’s length or if the capacity computation overflows usize.

Source

pub fn try_grow(&mut self, new_cap: usize) -> Result<(), CollectionAllocErr>

Re-allocate to set the capacity to max(new_cap, inline_size()).

Panics if new_cap is less than the vector’s length

Source

pub fn reserve(&mut self, additional: usize)

Reserve capacity for additional more elements to be inserted.

May reserve more space to avoid frequent reallocations.

Panics if the capacity computation overflows usize.

Source

pub fn try_reserve( &mut self, additional: usize, ) -> Result<(), CollectionAllocErr>

Reserve capacity for additional more elements to be inserted.

May reserve more space to avoid frequent reallocations.

Source

pub fn reserve_exact(&mut self, additional: usize)

Reserve the minimum capacity for additional more elements to be inserted.

Panics if the new capacity overflows usize.

Source

pub fn try_reserve_exact( &mut self, additional: usize, ) -> Result<(), CollectionAllocErr>

Reserve the minimum capacity for additional more elements to be inserted.

Source

pub fn shrink_to_fit(&mut self)

Shrink the capacity of the vector as much as possible.

When possible, this will move data from an external heap buffer to the vector’s inline storage.

Source

pub fn truncate(&mut self, len: usize)

Shorten the vector, keeping the first len elements and dropping the rest.

If len is greater than or equal to the vector’s current length, this has no effect.

This does not re-allocate. If you want the vector’s capacity to shrink, call shrink_to_fit after truncating.

Source

pub fn as_slice(&self) -> &[<A as Array>::Item]

Extracts a slice containing the entire vector.

Equivalent to &s[..].

Source

pub fn as_mut_slice(&mut self) -> &mut [<A as Array>::Item]

Extracts a mutable slice of the entire vector.

Equivalent to &mut s[..].

Source

pub fn swap_remove(&mut self, index: usize) -> <A as Array>::Item

Remove the element at position index, replacing it with the last element.

This does not preserve ordering, but is O(1).

Panics if index is out of bounds.

Source

pub fn clear(&mut self)

Remove all elements from the vector.

Source

pub fn remove(&mut self, index: usize) -> <A as Array>::Item

Remove and return the element at position index, shifting all elements after it to the left.

Panics if index is out of bounds.

Source

pub fn insert(&mut self, index: usize, element: <A as Array>::Item)

Insert an element at position index, shifting all elements after it to the right.

Panics if index > len.

Source

pub fn insert_many<I>(&mut self, index: usize, iterable: I)
where I: IntoIterator<Item = <A as Array>::Item>,

Insert multiple elements at position index, shifting all following elements toward the back.

Source

pub fn into_vec(self) -> Vec<<A as Array>::Item>

Convert a SmallVec to a Vec, without reallocating if the SmallVec has already spilled onto the heap.

Source

pub fn into_boxed_slice(self) -> Box<[<A as Array>::Item]>

Converts a SmallVec into a Box<[T]> without reallocating if the SmallVec has already spilled onto the heap.

Note that this will drop any excess capacity.

Source

pub fn into_inner(self) -> Result<A, SmallVec<A>>

Convert the SmallVec into an A if possible. Otherwise return Err(Self).

This method returns Err(Self) if the SmallVec is too short (and the A contains uninitialized elements), or if the SmallVec is too long (and all the elements were spilled to the heap).

Source

pub fn retain<F>(&mut self, f: F)
where F: FnMut(&mut <A as Array>::Item) -> bool,

Retains only the elements specified by the predicate.

In other words, remove all elements e such that f(&e) returns false. This method operates in place and preserves the order of the retained elements.

Source

pub fn retain_mut<F>(&mut self, f: F)
where F: FnMut(&mut <A as Array>::Item) -> bool,

Retains only the elements specified by the predicate.

This method is identical in behaviour to [retain]; it is included only to maintain api-compatability with std::Vec, where the methods are separate for historical reasons.

Source

pub fn dedup(&mut self)
where <A as Array>::Item: PartialEq,

Removes consecutive duplicate elements.

Source

pub fn dedup_by<F>(&mut self, same_bucket: F)
where F: FnMut(&mut <A as Array>::Item, &mut <A as Array>::Item) -> bool,

Removes consecutive duplicate elements using the given equality relation.

Source

pub fn dedup_by_key<F, K>(&mut self, key: F)
where F: FnMut(&mut <A as Array>::Item) -> K, K: PartialEq,

Removes consecutive elements that map to the same key.

Source

pub fn resize_with<F>(&mut self, new_len: usize, f: F)
where F: FnMut() -> <A as Array>::Item,

Resizes the SmallVec in-place so that len is equal to new_len.

If new_len is greater than len, the SmallVec is extended by the difference, with each additional slot filled with the result of calling the closure f. The return values from f will end up in the SmallVec in the order they have been generated.

If new_len is less than len, the SmallVec is simply truncated.

This method uses a closure to create new values on every push. If you’d rather Clone a given value, use resize. If you want to use the Default trait to generate values, you can pass Default::default() as the second argument.

Added for std::vec::Vec compatibility (added in Rust 1.33.0)

let mut vec : SmallVec<[_; 4]> = smallvec![1, 2, 3];
vec.resize_with(5, Default::default);
assert_eq!(&*vec, &[1, 2, 3, 0, 0]);

let mut vec : SmallVec<[_; 4]> = smallvec![];
let mut p = 1;
vec.resize_with(4, || { p *= 2; p });
assert_eq!(&*vec, &[2, 4, 8, 16]);
Source

pub unsafe fn from_raw_parts( ptr: *mut <A as Array>::Item, length: usize, capacity: usize, ) -> SmallVec<A>

Creates a SmallVec directly from the raw components of another SmallVec.

§Safety

This is highly unsafe, due to the number of invariants that aren’t checked:

  • ptr needs to have been previously allocated via SmallVec for its spilled storage (at least, it’s highly likely to be incorrect if it wasn’t).
  • ptr’s A::Item type needs to be the same size and alignment that it was allocated with
  • length needs to be less than or equal to capacity.
  • capacity needs to be the capacity that the pointer was allocated with.

Violating these may cause problems like corrupting the allocator’s internal data structures.

Additionally, capacity must be greater than the amount of inline storage A has; that is, the new SmallVec must need to spill over into heap allocated storage. This condition is asserted against.

The ownership of ptr is effectively transferred to the SmallVec which may then deallocate, reallocate or change the contents of memory pointed to by the pointer at will. Ensure that nothing else uses the pointer after calling this function.

§Examples
use std::mem;
use std::ptr;

fn main() {
    let mut v: SmallVec<[_; 1]> = smallvec![1, 2, 3];

    // Pull out the important parts of `v`.
    let p = v.as_mut_ptr();
    let len = v.len();
    let cap = v.capacity();
    let spilled = v.spilled();

    unsafe {
        // Forget all about `v`. The heap allocation that stored the
        // three values won't be deallocated.
        mem::forget(v);

        // Overwrite memory with [4, 5, 6].
        //
        // This is only safe if `spilled` is true! Otherwise, we are
        // writing into the old `SmallVec`'s inline storage on the
        // stack.
        assert!(spilled);
        for i in 0..len {
            ptr::write(p.add(i), 4 + i);
        }

        // Put everything back together into a SmallVec with a different
        // amount of inline storage, but which is still less than `cap`.
        let rebuilt = SmallVec::<[_; 2]>::from_raw_parts(p, len, cap);
        assert_eq!(&*rebuilt, &[4, 5, 6]);
    }
}
Source

pub fn as_ptr(&self) -> *const <A as Array>::Item

Returns a raw pointer to the vector’s buffer.

Source

pub fn as_mut_ptr(&mut self) -> *mut <A as Array>::Item

Returns a raw mutable pointer to the vector’s buffer.

Trait Implementations

Source§

impl<A> AsMut<[<A as Array>::Item]> for SmallVec<A>
where A: Array,

Source§

fn as_mut(&mut self) -> &mut [<A as Array>::Item]

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

impl<A> AsRef<[<A as Array>::Item]> for SmallVec<A>
where A: Array,

Source§

fn as_ref(&self) -> &[<A as Array>::Item]

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

impl<A> Borrow<[<A as Array>::Item]> for SmallVec<A>
where A: Array,

Source§

fn borrow(&self) -> &[<A as Array>::Item]

Immutably borrows from an owned value. Read more
Source§

impl<A> BorrowMut<[<A as Array>::Item]> for SmallVec<A>
where A: Array,

Source§

fn borrow_mut(&mut self) -> &mut [<A as Array>::Item]

Mutably borrows from an owned value. Read more
Source§

impl<A> Clone for SmallVec<A>
where A: Array, <A as Array>::Item: Clone,

Source§

fn clone(&self) -> SmallVec<A>

Returns a copy of the value. Read more
Source§

fn clone_from(&mut self, source: &SmallVec<A>)

Performs copy-assignment from source. Read more
Source§

impl<A> Debug for SmallVec<A>
where A: Array, <A as Array>::Item: Debug,

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), Error>

Formats the value using the given formatter. Read more
Source§

impl<D, A> Decodable<D> for SmallVec<A>
where D: Decoder, A: Array, <A as Array>::Item: Decodable<D>,

Source§

impl<A> Default for SmallVec<A>
where A: Array,

Source§

fn default() -> SmallVec<A>

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

impl<A> Deref for SmallVec<A>
where A: Array,

Source§

type Target = [<A as Array>::Item]

The resulting type after dereferencing.
Source§

fn deref(&self) -> &[<A as Array>::Item]

Dereferences the value.
Source§

impl<A> DerefMut for SmallVec<A>
where A: Array,

Source§

fn deref_mut(&mut self) -> &mut [<A as Array>::Item]

Mutably dereferences the value.
Source§

impl<A> Drop for SmallVec<A>
where A: Array,

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more
Source§

impl<S, A> Encodable<S> for SmallVec<A>
where S: Encoder, A: Array, <A as Array>::Item: Encodable<S>,

Source§

fn encode(&self, s: &mut S)

Source§

impl<A> ExpectOne<A> for SmallVec<A>
where A: Array,

Source§

fn expect_one(self, err: &'static str) -> <A as Array>::Item

Source§

impl<A> Extend<<A as Array>::Item> for SmallVec<A>
where A: Array,

Source§

fn extend<I>(&mut self, iterable: I)
where I: IntoIterator<Item = <A as Array>::Item>,

Extends a collection with the contents of an iterator. Read more
Source§

fn extend_one(&mut self, item: A)

🔬This is a nightly-only experimental API. (extend_one)
Extends a collection with exactly one element.
Source§

fn extend_reserve(&mut self, additional: usize)

🔬This is a nightly-only experimental API. (extend_one)
Reserves capacity in a collection for the given number of additional elements. Read more
Source§

impl<T, A> FlatMapInPlace<T> for SmallVec<A>
where A: Array<Item = T>,

Source§

fn flat_map_in_place<F, I>(&mut self, f: F)
where F: FnMut(T) -> I, I: IntoIterator<Item = T>,

Source§

impl<'a, A> From<&'a [<A as Array>::Item]> for SmallVec<A>
where A: Array, <A as Array>::Item: Clone,

Source§

fn from(slice: &'a [<A as Array>::Item]) -> SmallVec<A>

Converts to this type from the input type.
Source§

impl<A> From<A> for SmallVec<A>
where A: Array,

Source§

fn from(array: A) -> SmallVec<A>

Converts to this type from the input type.
Source§

impl<A> From<Vec<<A as Array>::Item>> for SmallVec<A>
where A: Array,

Source§

fn from(vec: Vec<<A as Array>::Item>) -> SmallVec<A>

Converts to this type from the input type.
Source§

impl<A> FromIterator<<A as Array>::Item> for SmallVec<A>
where A: Array,

Source§

fn from_iter<I>(iterable: I) -> SmallVec<A>
where I: IntoIterator<Item = <A as Array>::Item>,

Creates a value from an iterator. Read more
Source§

impl<A> Hash for SmallVec<A>
where A: Array, <A as Array>::Item: Hash,

Source§

fn hash<H>(&self, state: &mut H)
where H: Hasher,

Feeds this value into the given Hasher. Read more
1.3.0 · Source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

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

impl<A, const N: usize, CTX> HashStable<CTX> for SmallVec<[A; N]>
where A: HashStable<CTX>,

Source§

fn hash_stable(&self, ctx: &mut CTX, hasher: &mut StableHasher<SipHasher128>)

Source§

impl<A, I> Index<I> for SmallVec<A>
where A: Array, I: SliceIndex<[<A as Array>::Item]>,

Source§

type Output = <I as SliceIndex<[<A as Array>::Item]>>::Output

The returned type after indexing.
Source§

fn index(&self, index: I) -> &<I as SliceIndex<[<A as Array>::Item]>>::Output

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

impl<A, I> IndexMut<I> for SmallVec<A>
where A: Array, I: SliceIndex<[<A as Array>::Item]>,

Source§

fn index_mut( &mut self, index: I, ) -> &mut <I as SliceIndex<[<A as Array>::Item]>>::Output

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

impl<A> IntoIterator for SmallVec<A>
where A: Array,

Source§

type IntoIter = IntoIter<A>

Which kind of iterator are we turning this into?
Source§

type Item = <A as Array>::Item

The type of the elements being iterated over.
Source§

fn into_iter(self) -> IntoIter<A>

Creates an iterator from a value. Read more
Source§

impl<A> Ord for SmallVec<A>
where A: Array, <A as Array>::Item: Ord,

Source§

fn cmp(&self, other: &SmallVec<A>) -> Ordering

This method returns an Ordering between self and other. Read more
1.21.0 · Source§

fn max(self, other: Self) -> Self
where Self: Sized,

Compares and returns the maximum of two values. Read more
1.21.0 · Source§

fn min(self, other: Self) -> Self
where Self: Sized,

Compares and returns the minimum of two values. Read more
1.50.0 · Source§

fn clamp(self, min: Self, max: Self) -> Self
where Self: Sized,

Restrict a value to a certain interval. Read more
Source§

impl<A, B> PartialEq<SmallVec<B>> for SmallVec<A>
where A: Array, B: Array, <A as Array>::Item: PartialEq<<B as Array>::Item>,

Source§

fn eq(&self, other: &SmallVec<B>) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl<A> PartialOrd for SmallVec<A>
where A: Array, <A as Array>::Item: PartialOrd,

Source§

fn partial_cmp(&self, other: &SmallVec<A>) -> Option<Ordering>

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

fn lt(&self, other: &Rhs) -> bool

Tests less than (for self and other) and is used by the < operator. Read more
1.0.0 · Source§

fn le(&self, other: &Rhs) -> bool

Tests less than or equal to (for self and other) and is used by the <= operator. Read more
1.0.0 · Source§

fn gt(&self, other: &Rhs) -> bool

Tests greater than (for self and other) and is used by the > operator. Read more
1.0.0 · Source§

fn ge(&self, other: &Rhs) -> bool

Tests greater than or equal to (for self and other) and is used by the >= operator. Read more
Source§

impl<I, T, const N: usize> TypeVisitable<I> for SmallVec<[T; N]>
where I: Interner, T: TypeVisitable<I>,

Source§

fn visit_with<V>(&self, visitor: &mut V) -> <V as TypeVisitor<I>>::Result
where V: TypeVisitor<I>,

The entry point for visiting. To visit a value t with a visitor v call: t.visit_with(v). Read more
Source§

impl<A> DynSend for SmallVec<A>
where A: Array + DynSend,

Source§

impl<A> DynSync for SmallVec<A>
where A: Array + DynSync,

Source§

impl<A> Eq for SmallVec<A>
where A: Array, <A as Array>::Item: Eq,

Source§

impl<A> Send for SmallVec<A>
where A: Array, <A as Array>::Item: Send,