From 991919e71f048f9321e702512248e11c6c5fef70 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Fri, 18 Jun 2021 22:37:03 +0300 Subject: internal: add index to minicore --- crates/test_utils/src/minicore.rs | 43 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) (limited to 'crates/test_utils') diff --git a/crates/test_utils/src/minicore.rs b/crates/test_utils/src/minicore.rs index 769028580..71f07d38a 100644 --- a/crates/test_utils/src/minicore.rs +++ b/crates/test_utils/src/minicore.rs @@ -15,6 +15,7 @@ //! range: //! deref: sized //! deref_mut: deref +//! index: sized //! fn: //! pin: //! future: pin @@ -167,6 +168,48 @@ pub mod ops { }; // endregion:deref + // region:index + mod index { + #[lang = "index"] + pub trait Index { + type Output: ?Sized; + fn index(&self, index: Idx) -> &Self::Output; + } + #[lang = "index_mut"] + pub trait IndexMut: Index { + fn index_mut(&mut self, index: Idx) -> &mut Self::Output; + } + + // region:slice + impl Index for [T] + where + I: SliceIndex<[T]>, + { + type Output = I::Output; + fn index(&self, index: I) -> &I::Output { + loop {} + } + } + impl IndexMut for [T] + where + I: SliceIndex<[T]>, + { + fn index_mut(&mut self, index: I) -> &mut I::Output { + loop {} + } + } + + pub unsafe trait SliceIndex { + type Output: ?Sized; + } + unsafe impl SliceIndex<[T]> for usize { + type Output = T; + } + // endregion:slice + } + pub use self::index::{Index, IndexMut}; + // endregion:index + // region:range mod range { #[lang = "RangeFull"] -- cgit v1.2.3