diff options
| author | Matthias Krüger <matthias.krueger@famsik.de> | 2024-01-26 23:15:50 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2024-01-26 23:15:50 +0100 |
| commit | b31bf24908ef9e4b7e2236eaa133d3d22dbd5912 (patch) | |
| tree | 3bc92a1659667617de649d100b9fda15195bcb8c | |
| parent | 346397d081d289db20bc5cbdc23c96e00e60825f (diff) | |
| parent | 00ada8e30cb32a45dcac70630a8d4645a3ab393b (diff) | |
| download | rust-b31bf24908ef9e4b7e2236eaa133d3d22dbd5912.tar.gz rust-b31bf24908ef9e4b7e2236eaa133d3d22dbd5912.zip | |
Rollup merge of #119800 - dev-ardi:tmp, r=wesleywiser
Document `rustc_index::vec::IndexVec` Document a few of the methods. Part of https://github.com/rust-lang/rust/issues/93792.
| -rw-r--r-- | compiler/rustc_index/src/vec.rs | 7 |
1 files changed, 7 insertions, 0 deletions
diff --git a/compiler/rustc_index/src/vec.rs b/compiler/rustc_index/src/vec.rs index 66c5cc774b2..d876174e620 100644 --- a/compiler/rustc_index/src/vec.rs +++ b/compiler/rustc_index/src/vec.rs @@ -12,10 +12,13 @@ use std::vec; use crate::{Idx, IndexSlice}; /// An owned contiguous collection of `T`s, indexed by `I` rather than by `usize`. +/// Its purpose is to avoid mixing indexes. /// /// While it's possible to use `u32` or `usize` directly for `I`, /// you almost certainly want to use a [`newtype_index!`]-generated type instead. /// +/// This allows to index the IndexVec with the new index type. +/// /// [`newtype_index!`]: ../macro.newtype_index.html #[derive(Clone, PartialEq, Eq, Hash)] #[repr(transparent)] @@ -25,11 +28,13 @@ pub struct IndexVec<I: Idx, T> { } impl<I: Idx, T> IndexVec<I, T> { + /// Constructs a new, empty `IndexVec<I, T>`. #[inline] pub const fn new() -> Self { IndexVec::from_raw(Vec::new()) } + /// Constructs a new `IndexVec<I, T>` from a `Vec<T>`. #[inline] pub const fn from_raw(raw: Vec<T>) -> Self { IndexVec { raw, _marker: PhantomData } @@ -59,6 +64,7 @@ impl<I: Idx, T> IndexVec<I, T> { IndexVec::from_raw(vec![elem; universe.len()]) } + /// Creates a new IndexVec with n copies of the `elem`. #[inline] pub fn from_elem_n(elem: T, n: usize) -> Self where @@ -85,6 +91,7 @@ impl<I: Idx, T> IndexVec<I, T> { IndexSlice::from_raw_mut(&mut self.raw) } + /// Pushes an element to the array returning the index where it was pushed to. #[inline] pub fn push(&mut self, d: T) -> I { let idx = self.next_index(); |
