diff options
| author | Jorge Aparicio <japaricious@gmail.com> | 2015-01-01 14:53:20 -0500 |
|---|---|---|
| committer | Jorge Aparicio <japaricious@gmail.com> | 2015-01-02 12:19:59 -0500 |
| commit | 64b7c22c46b204520a6fae1c5cd750a3d3c6a66a (patch) | |
| tree | 6e9a504759c5ac42f747c5739b4173d6646cd8c8 /src/libstd | |
| parent | d55577255434d1a9969b74cc4ac5dff4c04d6054 (diff) | |
| download | rust-64b7c22c46b204520a6fae1c5cd750a3d3c6a66a.tar.gz rust-64b7c22c46b204520a6fae1c5cd750a3d3c6a66a.zip | |
core: use assoc types in `Deref[Mut]`
Diffstat (limited to 'src/libstd')
| -rw-r--r-- | src/libstd/collections/hash/map.rs | 2 | ||||
| -rw-r--r-- | src/libstd/collections/hash/table.rs | 16 | ||||
| -rw-r--r-- | src/libstd/io/stdio.rs | 6 | ||||
| -rw-r--r-- | src/libstd/rt/exclusive.rs | 6 | ||||
| -rw-r--r-- | src/libstd/sync/mutex.rs | 6 | ||||
| -rw-r--r-- | src/libstd/sync/rwlock.rs | 10 |
6 files changed, 28 insertions, 18 deletions
diff --git a/src/libstd/collections/hash/map.rs b/src/libstd/collections/hash/map.rs index f6063df5434..e61b9af5a12 100644 --- a/src/libstd/collections/hash/map.rs +++ b/src/libstd/collections/hash/map.rs @@ -311,7 +311,7 @@ fn search_hashed<K, V, M, F>(table: M, hash: SafeHash, mut is_match: F) -> SearchResult<K, V, M> where - M: Deref<RawTable<K, V>>, + M: Deref<Target=RawTable<K, V>>, F: FnMut(&K) -> bool, { let size = table.size(); diff --git a/src/libstd/collections/hash/table.rs b/src/libstd/collections/hash/table.rs index 6938ab9b0b6..a687ba3da8d 100644 --- a/src/libstd/collections/hash/table.rs +++ b/src/libstd/collections/hash/table.rs @@ -210,7 +210,7 @@ impl<K, V, M> Bucket<K, V, M> { } } -impl<K, V, M: Deref<RawTable<K, V>>> Bucket<K, V, M> { +impl<K, V, M: Deref<Target=RawTable<K, V>>> Bucket<K, V, M> { pub fn new(table: M, hash: SafeHash) -> Bucket<K, V, M> { Bucket::at_index(table, hash.inspect() as uint) } @@ -279,7 +279,7 @@ impl<K, V, M: Deref<RawTable<K, V>>> Bucket<K, V, M> { } } -impl<K, V, M: Deref<RawTable<K, V>>> EmptyBucket<K, V, M> { +impl<K, V, M: Deref<Target=RawTable<K, V>>> EmptyBucket<K, V, M> { #[inline] pub fn next(self) -> Bucket<K, V, M> { let mut bucket = self.into_bucket(); @@ -315,7 +315,7 @@ impl<K, V, M: Deref<RawTable<K, V>>> EmptyBucket<K, V, M> { } } -impl<K, V, M: DerefMut<RawTable<K, V>>> EmptyBucket<K, V, M> { +impl<K, V, M: Deref<Target=RawTable<K, V>> + DerefMut> EmptyBucket<K, V, M> { /// Puts given key and value pair, along with the key's hash, /// into this bucket in the hashtable. Note how `self` is 'moved' into /// this function, because this slot will no longer be empty when @@ -337,7 +337,7 @@ impl<K, V, M: DerefMut<RawTable<K, V>>> EmptyBucket<K, V, M> { } } -impl<K, V, M: Deref<RawTable<K, V>>> FullBucket<K, V, M> { +impl<K, V, M: Deref<Target=RawTable<K, V>>> FullBucket<K, V, M> { #[inline] pub fn next(self) -> Bucket<K, V, M> { let mut bucket = self.into_bucket(); @@ -384,7 +384,7 @@ impl<K, V, M: Deref<RawTable<K, V>>> FullBucket<K, V, M> { } } -impl<K, V, M: DerefMut<RawTable<K, V>>> FullBucket<K, V, M> { +impl<K, V, M: Deref<Target=RawTable<K, V>> + DerefMut> FullBucket<K, V, M> { /// Removes this bucket's key and value from the hashtable. /// /// This works similarly to `put`, building an `EmptyBucket` out of the @@ -428,7 +428,7 @@ impl<K, V, M: DerefMut<RawTable<K, V>>> FullBucket<K, V, M> { } } -impl<'t, K, V, M: Deref<RawTable<K, V>> + 't> FullBucket<K, V, M> { +impl<'t, K, V, M: Deref<Target=RawTable<K, V>> + 't> FullBucket<K, V, M> { /// Exchange a bucket state for immutable references into the table. /// Because the underlying reference to the table is also consumed, /// no further changes to the structure of the table are possible; @@ -442,7 +442,7 @@ impl<'t, K, V, M: Deref<RawTable<K, V>> + 't> FullBucket<K, V, M> { } } -impl<'t, K, V, M: DerefMut<RawTable<K, V>> + 't> FullBucket<K, V, M> { +impl<'t, K, V, M: Deref<Target=RawTable<K, V>> + DerefMut + 't> FullBucket<K, V, M> { /// This works similarly to `into_refs`, exchanging a bucket state /// for mutable references into the table. pub fn into_mut_refs(self) -> (&'t mut K, &'t mut V) { @@ -463,7 +463,7 @@ impl<K, V, M> BucketState<K, V, M> { } } -impl<K, V, M: Deref<RawTable<K, V>>> GapThenFull<K, V, M> { +impl<K, V, M: Deref<Target=RawTable<K, V>>> GapThenFull<K, V, M> { #[inline] pub fn full(&self) -> &FullBucket<K, V, M> { &self.full diff --git a/src/libstd/io/stdio.rs b/src/libstd/io/stdio.rs index b7d069eb19e..e58ff1c3ac4 100644 --- a/src/libstd/io/stdio.rs +++ b/src/libstd/io/stdio.rs @@ -117,13 +117,15 @@ pub struct StdinReaderGuard<'a> { inner: MutexGuard<'a, RaceBox>, } -impl<'a> Deref<BufferedReader<StdReader>> for StdinReaderGuard<'a> { +impl<'a> Deref for StdinReaderGuard<'a> { + type Target = BufferedReader<StdReader>; + fn deref(&self) -> &BufferedReader<StdReader> { &self.inner.0 } } -impl<'a> DerefMut<BufferedReader<StdReader>> for StdinReaderGuard<'a> { +impl<'a> DerefMut for StdinReaderGuard<'a> { fn deref_mut(&mut self) -> &mut BufferedReader<StdReader> { &mut self.inner.0 } diff --git a/src/libstd/rt/exclusive.rs b/src/libstd/rt/exclusive.rs index 88bdb29caec..e44511169ab 100644 --- a/src/libstd/rt/exclusive.rs +++ b/src/libstd/rt/exclusive.rs @@ -74,10 +74,12 @@ impl<'a, T: Send> ExclusiveGuard<'a, T> { } } -impl<'a, T: Send> Deref<T> for ExclusiveGuard<'a, T> { +impl<'a, T: Send> Deref for ExclusiveGuard<'a, T> { + type Target = T; + fn deref(&self) -> &T { &*self._data } } -impl<'a, T: Send> DerefMut<T> for ExclusiveGuard<'a, T> { +impl<'a, T: Send> DerefMut for ExclusiveGuard<'a, T> { fn deref_mut(&mut self) -> &mut T { &mut *self._data } } diff --git a/src/libstd/sync/mutex.rs b/src/libstd/sync/mutex.rs index 52004bb4a8f..08980eb01c6 100644 --- a/src/libstd/sync/mutex.rs +++ b/src/libstd/sync/mutex.rs @@ -288,12 +288,14 @@ impl<'mutex, T> MutexGuard<'mutex, T> { } } -impl<'mutex, T> Deref<T> for MutexGuard<'mutex, T> { +impl<'mutex, T> Deref for MutexGuard<'mutex, T> { + type Target = T; + fn deref<'a>(&'a self) -> &'a T { unsafe { &*self.__data.get() } } } -impl<'mutex, T> DerefMut<T> for MutexGuard<'mutex, T> { +impl<'mutex, T> DerefMut for MutexGuard<'mutex, T> { fn deref_mut<'a>(&'a mut self) -> &'a mut T { unsafe { &mut *self.__data.get() } } diff --git a/src/libstd/sync/rwlock.rs b/src/libstd/sync/rwlock.rs index 7f3c77c97ad..7478e903355 100644 --- a/src/libstd/sync/rwlock.rs +++ b/src/libstd/sync/rwlock.rs @@ -326,13 +326,17 @@ impl<'rwlock, T> RWLockWriteGuard<'rwlock, T> { } } -impl<'rwlock, T> Deref<T> for RWLockReadGuard<'rwlock, T> { +impl<'rwlock, T> Deref for RWLockReadGuard<'rwlock, T> { + type Target = T; + fn deref(&self) -> &T { unsafe { &*self.__data.get() } } } -impl<'rwlock, T> Deref<T> for RWLockWriteGuard<'rwlock, T> { +impl<'rwlock, T> Deref for RWLockWriteGuard<'rwlock, T> { + type Target = T; + fn deref(&self) -> &T { unsafe { &*self.__data.get() } } } -impl<'rwlock, T> DerefMut<T> for RWLockWriteGuard<'rwlock, T> { +impl<'rwlock, T> DerefMut for RWLockWriteGuard<'rwlock, T> { fn deref_mut(&mut self) -> &mut T { unsafe { &mut *self.__data.get() } } |
