File tree Expand file tree Collapse file tree 2 files changed +39
-1
lines changed
branches/try/src/libcollections Expand file tree Collapse file tree 2 files changed +39
-1
lines changed Original file line number Diff line number Diff line change 2
2
refs/heads/master: 07d86b46a949a94223da714e35b343243e4ecce4
3
3
refs/heads/snap-stage1: e33de59e47c5076a89eadeb38f4934f58a3618a6
4
4
refs/heads/snap-stage3: a86d9ad15e339ab343a12513f9c90556f677b9ca
5
- refs/heads/try: 11b8f9c3f666e3a0533da0f3a00188689fc60cb4
5
+ refs/heads/try: 8f71cb06bc019af707f119b5dda3d96a5ca1330c
6
6
refs/tags/release-0.1: 1f5c5126e96c79d22cb7862f75304136e204f105
7
7
refs/heads/ndm: f3868061cd7988080c30d6d5bf352a5a5fe2460b
8
8
refs/heads/try2: 147ecfdd8221e4a4d4e090486829a06da1e0ca3c
Original file line number Diff line number Diff line change @@ -502,6 +502,21 @@ impl<S: Writer, T: Hash<S>> Hash<S> for TrieMap<T> {
502
502
}
503
503
}
504
504
505
+ impl < T > Index < uint , T > for TrieMap < T > {
506
+ #[ inline]
507
+ fn index < ' a > ( & ' a self , i : & uint ) -> & ' a T {
508
+ self . find ( i) . expect ( "key not present" )
509
+ }
510
+ }
511
+
512
+ // FIXME(#12825) Indexing will always try IndexMut first and that causes issues.
513
+ /*impl<T> IndexMut<uint, T> for TrieMap<T> {
514
+ #[inline]
515
+ fn index_mut<'a>(&'a mut self, i: &uint) -> &'a mut T {
516
+ self.find_mut(i).expect("key not present")
517
+ }
518
+ }*/
519
+
505
520
/// A set implemented as a radix trie.
506
521
///
507
522
/// # Example
@@ -1391,6 +1406,29 @@ mod test_map {
1391
1406
assert ! ( map_str == "{1: a, 2: b}" . to_string( ) ) ;
1392
1407
assert_eq ! ( format!( "{}" , empty) , "{}" . to_string( ) ) ;
1393
1408
}
1409
+
1410
+ #[ test]
1411
+ fn test_index ( ) {
1412
+ let mut map = TrieMap :: new ( ) ;
1413
+
1414
+ map. insert ( 1 , 2 i) ;
1415
+ map. insert ( 2 , 1 i) ;
1416
+ map. insert ( 3 , 4 i) ;
1417
+
1418
+ assert_eq ! ( map[ 2 ] , 1 ) ;
1419
+ }
1420
+
1421
+ #[ test]
1422
+ #[ should_fail]
1423
+ fn test_index_nonexistent ( ) {
1424
+ let mut map = TrieMap :: new ( ) ;
1425
+
1426
+ map. insert ( 1 , 2 i) ;
1427
+ map. insert ( 2 , 1 i) ;
1428
+ map. insert ( 3 , 4 i) ;
1429
+
1430
+ map[ 4 ] ;
1431
+ }
1394
1432
}
1395
1433
1396
1434
#[ cfg( test) ]
You can’t perform that action at this time.
0 commit comments