Skip to content

Commit a6eb263

Browse files
committed
addressed greeter's comments
1 parent e2ba6f3 commit a6eb263

File tree

2 files changed

+21
-38
lines changed

2 files changed

+21
-38
lines changed

src/libstd/collections/hashmap/map.rs

+2-3
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@ use ops::Index;
2929
use super::table;
3030
use super::table::{
3131
Bucket,
32-
BucketWithTable,
3332
Empty,
3433
Full,
3534
FullBucket,
@@ -423,8 +422,8 @@ impl<K, V, M> SearchResult<K, V, M> {
423422
}
424423
}
425424

426-
/// A newtyped mutable reference to the hashmap that can't be constructed
427-
/// by the user to prevent changes to the visible interface of HashMap.
425+
/// A newtyped mutable reference to the hashmap that implements Deref to avoid
426+
/// changes to the visible interface of HashMap.
428427
/// Used internally because it's accepted by the search functions above.
429428
struct MapMutRef<'a, K: 'a, V: 'a, H: 'a> {
430429
map_ref: &'a mut HashMap<K, V, H>

src/libstd/collections/hashmap/table.rs

+19-35
Original file line numberDiff line numberDiff line change
@@ -182,56 +182,40 @@ impl<'t, K, V> DerefMut<RawTable<K, V>> for &'t mut RawTable<K, V> {
182182
}
183183
}
184184

185-
/// A bucket that holds a reference to the table
186-
pub trait BucketWithTable<M> {
185+
// Buckets hold references to the table.
186+
impl<K, V, M> FullBucket<K, V, M> {
187187
/// Borrow a reference to the table.
188-
fn table(&self) -> &M;
189-
190-
/// Move out the reference to the table.
191-
fn into_table(self) -> M;
192-
193-
/// Get the raw index.
194-
fn index(&self) -> uint;
195-
}
196-
197-
impl<K, V, M> BucketWithTable<M> for FullBucket<K, V, M> {
198-
fn table(&self) -> &M {
188+
pub fn table(&self) -> &M {
199189
&self.table
200190
}
201-
202-
fn into_table(self) -> M {
191+
/// Move out the reference to the table.
192+
pub fn into_table(self) -> M {
203193
self.table
204194
}
205-
206-
fn index(&self) -> uint {
195+
/// Get the raw index.
196+
pub fn index(&self) -> uint {
207197
self.idx
208198
}
209199
}
210200

211-
impl<K, V, M> BucketWithTable<M> for EmptyBucket<K, V, M> {
212-
fn table(&self) -> &M {
201+
impl<K, V, M> EmptyBucket<K, V, M> {
202+
/// Borrow a reference to the table.
203+
pub fn table(&self) -> &M {
213204
&self.table
214205
}
215-
216-
fn into_table(self) -> M {
206+
/// Move out the reference to the table.
207+
pub fn into_table(self) -> M {
217208
self.table
218209
}
219-
220-
fn index(&self) -> uint {
221-
self.idx
222-
}
223210
}
224211

225-
impl<K, V, M> BucketWithTable<M> for Bucket<K, V, M> {
226-
fn table(&self) -> &M {
227-
&self.table
228-
}
229-
230-
fn into_table(self) -> M {
212+
impl<K, V, M> Bucket<K, V, M> {
213+
/// Move out the reference to the table.
214+
pub fn into_table(self) -> M {
231215
self.table
232216
}
233-
234-
fn index(&self) -> uint {
217+
/// Get the raw index.
218+
pub fn index(&self) -> uint {
235219
self.idx
236220
}
237221
}
@@ -454,7 +438,7 @@ impl<K, V, M: DerefMut<RawTable<K, V>>> FullBucket<K, V, M> {
454438
}
455439
}
456440

457-
impl<'t, K, V, M: Deref<RawTable<K, V>>> FullBucket<K, V, M> {
441+
impl<'t, K, V, M: Deref<RawTable<K, V>> + 't> FullBucket<K, V, M> {
458442
/// Exchange a bucket state for immutable references into the table.
459443
/// Because the underlying reference to the table is also consumed,
460444
/// no further changes to the structure of the table are possible;
@@ -468,7 +452,7 @@ impl<'t, K, V, M: Deref<RawTable<K, V>>> FullBucket<K, V, M> {
468452
}
469453
}
470454

471-
impl<'t, K, V, M: DerefMut<RawTable<K, V>>> FullBucket<K, V, M> {
455+
impl<'t, K, V, M: DerefMut<RawTable<K, V>> + 't> FullBucket<K, V, M> {
472456
/// This works similarly to `into_refs`, exchanging a bucket state
473457
/// for mutable references into the table.
474458
pub fn into_mut_refs(self) -> (&'t mut K, &'t mut V) {

0 commit comments

Comments
 (0)