mirror of
https://github.com/rust-lang/rust.git
synced 2024-11-25 08:13:41 +00:00
Fix some mistakes + new doc
This commit is contained in:
parent
1bf3aee381
commit
ee8510e4e1
@ -17,15 +17,13 @@ use crate::{Idx, IndexSlice};
|
|||||||
/// While it's possible to use `u32` or `usize` directly for `I`,
|
/// While it's possible to use `u32` or `usize` directly for `I`,
|
||||||
/// you almost certainly want to use a [`newtype_index!`]-generated type instead.
|
/// you almost certainly want to use a [`newtype_index!`]-generated type instead.
|
||||||
///
|
///
|
||||||
/// This allows to index the IndexVec with the new index type
|
/// This allows to index the IndexVec with the new index type.
|
||||||
///
|
|
||||||
///
|
|
||||||
/// [`newtype_index!`]: ../macro.newtype_index.html
|
/// [`newtype_index!`]: ../macro.newtype_index.html
|
||||||
#[derive(Clone, PartialEq, Eq, Hash)]
|
#[derive(Clone, PartialEq, Eq, Hash)]
|
||||||
#[repr(transparent)]
|
#[repr(transparent)]
|
||||||
pub struct IndexVec<I: Idx, T> {
|
pub struct IndexVec<I: Idx, T> {
|
||||||
pub raw: Vec<T>,
|
pub raw: Vec<T>,
|
||||||
_marker: PhantomData<I>,
|
_marker: PhantomData<fn(&I)>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<I: Idx, T> IndexVec<I, T> {
|
impl<I: Idx, T> IndexVec<I, T> {
|
||||||
@ -35,7 +33,7 @@ impl<I: Idx, T> IndexVec<I, T> {
|
|||||||
IndexVec::from_raw(Vec::new())
|
IndexVec::from_raw(Vec::new())
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Constructs a new `IndexVec<I, T>` from a `Vec<T>`
|
/// Constructs a new `IndexVec<I, T>` from a `Vec<T>`.
|
||||||
#[inline]
|
#[inline]
|
||||||
pub const fn from_raw(raw: Vec<T>) -> Self {
|
pub const fn from_raw(raw: Vec<T>) -> Self {
|
||||||
IndexVec { raw, _marker: PhantomData }
|
IndexVec { raw, _marker: PhantomData }
|
||||||
@ -65,7 +63,7 @@ impl<I: Idx, T> IndexVec<I, T> {
|
|||||||
IndexVec::from_raw(vec![elem; universe.len()])
|
IndexVec::from_raw(vec![elem; universe.len()])
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Creates a new IndexVec
|
/// Creates a new IndexVec with n copies of the `elem`.
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn from_elem_n(elem: T, n: usize) -> Self
|
pub fn from_elem_n(elem: T, n: usize) -> Self
|
||||||
where
|
where
|
||||||
@ -92,6 +90,7 @@ impl<I: Idx, T> IndexVec<I, T> {
|
|||||||
IndexSlice::from_raw_mut(&mut self.raw)
|
IndexSlice::from_raw_mut(&mut self.raw)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Pushes an element to the array returning the index where it was pushed to.
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn push(&mut self, d: T) -> I {
|
pub fn push(&mut self, d: T) -> I {
|
||||||
let idx = self.next_index();
|
let idx = self.next_index();
|
||||||
|
Loading…
Reference in New Issue
Block a user