@@ -13,7 +13,7 @@ use core::fmt::Debug;
13
13
use core:: hash:: { Hash , Hasher } ;
14
14
use core:: iter:: { FromIterator , Peekable , FusedIterator } ;
15
15
use core:: marker:: PhantomData ;
16
- use core:: ops:: Index ;
16
+ use core:: ops:: { Index , InPlace , Place , Placer } ;
17
17
use core:: { fmt, intrinsics, mem, ptr} ;
18
18
19
19
use borrow:: Borrow ;
@@ -447,6 +447,62 @@ impl<'a, K: 'a + Debug + Ord, V: 'a + Debug> Debug for OccupiedEntry<'a, K, V> {
447
447
}
448
448
}
449
449
450
+ /// A place for insertion to a `Entry`.
451
+ ///
452
+ /// See [`BTreeMap::entry`](struct.BTreeMap.html#method.entry) for details.
453
+ #[ must_use = "places do nothing unless written to with <- syntax" ]
454
+ #[ unstable( feature = "collection_placement" ,
455
+ reason = "struct name and placement protocol is subject to change" ,
456
+ issue = "30172" ) ]
457
+ #[ derive( Debug ) ]
458
+ pub struct EntryPlace < ' a , K : ' a + Debug + Ord , V : ' a > {
459
+ entry : Entry < ' a , K , V > ,
460
+ value : V ,
461
+ }
462
+
463
+ #[ unstable( feature = "collection_placement" ,
464
+ reason = "placement protocol is subject to change" ,
465
+ issue = "30172" ) ]
466
+ impl < ' a , K , V > Placer < V > for Entry < ' a , K , V >
467
+ where K : ' a + Debug + Ord {
468
+ type Place = EntryPlace < ' a , K , V > ;
469
+
470
+ fn make_place ( self ) -> EntryPlace < ' a , K , V > {
471
+ let uninit = unsafe { mem:: uninitialized ( ) } ;
472
+ EntryPlace { entry : self , value : uninit }
473
+ }
474
+ }
475
+
476
+ #[ unstable( feature = "collection_placement" ,
477
+ reason = "placement protocol is subject to change" ,
478
+ issue = "30172" ) ]
479
+ impl < ' a , K , V > Place < V > for EntryPlace < ' a , K , V >
480
+ where K : ' a + Debug + Ord {
481
+ fn pointer ( & mut self ) -> * mut V {
482
+ & mut self . value
483
+ }
484
+ }
485
+
486
+ #[ unstable( feature = "collection_placement" ,
487
+ reason = "placement protocol is subject to change" ,
488
+ issue = "30172" ) ]
489
+ impl < ' a , K , V > InPlace < V > for EntryPlace < ' a , K , V >
490
+ where K : ' a + Debug + Ord {
491
+ type Owner = ( ) ;
492
+
493
+ unsafe fn finalize ( self ) {
494
+ match self . entry {
495
+ Occupied ( mut o) => {
496
+ o. insert ( self . value ) ;
497
+ }
498
+ Vacant ( v) => {
499
+ v. insert ( self . value ) ;
500
+ }
501
+ }
502
+ }
503
+ }
504
+
505
+
450
506
// An iterator for merging two sorted sequences into one
451
507
struct MergeIter < K , V , I : Iterator < Item = ( K , V ) > > {
452
508
left : Peekable < I > ,
0 commit comments