@@ -3,7 +3,7 @@ use super::{Bucket, Entries, IndexMap, Iter, IterMut, Keys, Values, ValuesMut};
3
3
use core:: cmp:: Ordering ;
4
4
use core:: fmt;
5
5
use core:: hash:: { Hash , Hasher } ;
6
- use core:: ops:: { self , Index , IndexMut } ;
6
+ use core:: ops:: { self , Deref , DerefMut , Index , IndexMut } ;
7
7
8
8
/// A dynamically-sized slice of key-value pairs in an `IndexMap`.
9
9
///
@@ -44,13 +44,45 @@ impl<K, V, S> IndexMap<K, V, S> {
44
44
}
45
45
}
46
46
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 > {
48
74
/// 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 > {
50
76
Slice :: from_slice ( self . iter . as_slice ( ) )
51
77
}
52
78
}
53
79
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
+
54
86
impl < ' a , K , V > IterMut < ' a , K , V > {
55
87
/// Returns a slice of the remaining entries in the iterator.
56
88
///
0 commit comments