@@ -3,7 +3,7 @@ use super::{Bucket, Entries, IndexMap, Iter, IterMut, Keys, Values, ValuesMut};
33use core:: cmp:: Ordering ;
44use core:: fmt;
55use core:: hash:: { Hash , Hasher } ;
6- use core:: ops:: { self , Index , IndexMut } ;
6+ use core:: ops:: { self , Deref , DerefMut , Index , IndexMut } ;
77
88/// A dynamically-sized slice of key-value pairs in an `IndexMap`.
99///
@@ -44,13 +44,45 @@ impl<K, V, S> IndexMap<K, V, S> {
4444 }
4545}
4646
47- impl < K , V > Iter < ' _ , K , V > {
47+ impl < K , V , S > Deref for IndexMap < K , V , S > {
48+ type Target = Slice < K , V > ;
49+
50+ fn deref ( & self ) -> & Self :: Target {
51+ self . as_slice ( )
52+ }
53+ }
54+
55+ impl < K , V , S > DerefMut for IndexMap < K , V , S > {
56+ fn deref_mut ( & mut self ) -> & mut Self :: Target {
57+ self . as_mut_slice ( )
58+ }
59+ }
60+
61+ impl < K , V , S > AsRef < Slice < K , V > > for IndexMap < K , V , S > {
62+ fn as_ref ( & self ) -> & Slice < K , V > {
63+ self . as_slice ( )
64+ }
65+ }
66+
67+ impl < K , V , S > AsMut < Slice < K , V > > for IndexMap < K , V , S > {
68+ fn as_mut ( & mut self ) -> & mut Slice < K , V > {
69+ self . as_mut_slice ( )
70+ }
71+ }
72+
73+ impl < ' a , K , V > Iter < ' a , K , V > {
4874 /// Returns a slice of the remaining entries in the iterator.
49- pub fn as_slice ( & self ) -> & Slice < K , V > {
75+ pub fn as_slice ( & self ) -> & ' a Slice < K , V > {
5076 Slice :: from_slice ( self . iter . as_slice ( ) )
5177 }
5278}
5379
80+ impl < K , V > AsRef < Slice < K , V > > for Iter < ' _ , K , V > {
81+ fn as_ref ( & self ) -> & Slice < K , V > {
82+ self . as_slice ( )
83+ }
84+ }
85+
5486impl < ' a , K , V > IterMut < ' a , K , V > {
5587 /// Returns a slice of the remaining entries in the iterator.
5688 ///
0 commit comments