192f3ab15Sopenharmony_ciuse libc::c_int;
292f3ab15Sopenharmony_ciuse std::marker::PhantomData;
392f3ab15Sopenharmony_ci
492f3ab15Sopenharmony_ci/// A slot in a type's "extra data" structure.
592f3ab15Sopenharmony_ci///
692f3ab15Sopenharmony_ci/// It is parameterized over the type containing the extra data as well as the
792f3ab15Sopenharmony_ci/// type of the data in the slot.
892f3ab15Sopenharmony_cipub struct Index<T, U>(c_int, PhantomData<(T, U)>);
992f3ab15Sopenharmony_ci
1092f3ab15Sopenharmony_ciimpl<T, U> Copy for Index<T, U> {}
1192f3ab15Sopenharmony_ci
1292f3ab15Sopenharmony_ciimpl<T, U> Clone for Index<T, U> {
1392f3ab15Sopenharmony_ci    fn clone(&self) -> Index<T, U> {
1492f3ab15Sopenharmony_ci        *self
1592f3ab15Sopenharmony_ci    }
1692f3ab15Sopenharmony_ci}
1792f3ab15Sopenharmony_ci
1892f3ab15Sopenharmony_ciimpl<T, U> Index<T, U> {
1992f3ab15Sopenharmony_ci    /// Creates an `Index` from a raw integer index.
2092f3ab15Sopenharmony_ci    ///
2192f3ab15Sopenharmony_ci    /// # Safety
2292f3ab15Sopenharmony_ci    ///
2392f3ab15Sopenharmony_ci    /// The caller must ensure that the index correctly maps to a `U` value stored in a `T`.
2492f3ab15Sopenharmony_ci    pub unsafe fn from_raw(idx: c_int) -> Index<T, U> {
2592f3ab15Sopenharmony_ci        Index(idx, PhantomData)
2692f3ab15Sopenharmony_ci    }
2792f3ab15Sopenharmony_ci
2892f3ab15Sopenharmony_ci    #[allow(clippy::trivially_copy_pass_by_ref)]
2992f3ab15Sopenharmony_ci    pub fn as_raw(&self) -> c_int {
3092f3ab15Sopenharmony_ci        self.0
3192f3ab15Sopenharmony_ci    }
3292f3ab15Sopenharmony_ci}
33