charon_driver/hax/
index_vec.rs1use crate::hax::prelude::*;
2
3#[derive(Clone, Debug, Hash, PartialEq, Eq)]
4pub struct IndexVec<I: 'static, T: 'static> {
5 pub raw: Vec<T>,
6 _marker: std::marker::PhantomData<fn(_: &I)>,
7}
8
9impl<I: rustc_index::Idx, T: Sized> IndexVec<I, T> {
10 pub fn into_iter_enumerated(
11 self,
12 ) -> impl DoubleEndedIterator<Item = (I, T)> + ExactSizeIterator {
13 rustc_index::IndexVec::from_raw(self.raw).into_iter_enumerated()
14 }
15 pub fn into_iter(self) -> impl DoubleEndedIterator<Item = T> + ExactSizeIterator {
16 self.raw.into_iter()
17 }
18}
19
20impl<I: rustc_index::Idx, T: Sized> std::ops::Deref for IndexVec<I, T> {
21 type Target = rustc_index::IndexSlice<I, T>;
22 fn deref(&self) -> &Self::Target {
23 Self::Target::from_raw(&self.raw)
24 }
25}
26
27impl<I: rustc_index::Idx, T: Sized> std::ops::DerefMut for IndexVec<I, T> {
28 fn deref_mut(&mut self) -> &mut Self::Target {
29 Self::Target::from_raw_mut(&mut self.raw)
30 }
31}
32
33impl<I: rustc_index::Idx, T> From<rustc_index::IndexVec<I, T>> for IndexVec<I, T> {
34 fn from(val: rustc_index::IndexVec<I, T>) -> Self {
35 IndexVec {
36 raw: val.raw,
37 _marker: std::marker::PhantomData,
38 }
39 }
40}
41
42impl<S, J: rustc_index::Idx, I: rustc_index::Idx + SInto<S, J>, U: Clone, T: SInto<S, U>>
43 SInto<S, IndexVec<J, U>> for rustc_index::IndexSlice<I, T>
44{
45 fn sinto(&self, s: &S) -> IndexVec<J, U> {
46 IndexVec {
47 raw: self.raw.sinto(s),
48 _marker: std::marker::PhantomData,
49 }
50 }
51}
52
53impl<I, T> FromIterator<T> for IndexVec<I, T>
54where
55 I: rustc_index::Idx,
56{
57 #[inline]
58 fn from_iter<It: IntoIterator<Item = T>>(iter: It) -> Self {
59 Self {
60 raw: Vec::from_iter(iter),
61 _marker: std::marker::PhantomData,
62 }
63 }
64}