@@ -17,6 +17,9 @@ use crate::string::String;
17
17
18
18
use Cow :: * ;
19
19
20
+ // @FIXME check if used & needed
21
+ pub ( crate ) const BORROW_COOP_PREFERRED : bool = DEFAULT_COOP_PREFERRED ! ( ) ;
22
+
20
23
#[ stable( feature = "rust1" , since = "1.0.0" ) ]
21
24
impl < ' a , B : ?Sized , const COOP_PREFERRED : bool > Borrow < B > for Cow < ' a , B , COOP_PREFERRED >
22
25
where
@@ -344,9 +347,10 @@ where
344
347
345
348
#[ stable( feature = "rust1" , since = "1.0.0" ) ]
346
349
#[ rustc_const_unstable( feature = "const_deref" , issue = "88955" ) ]
347
- impl < B : ?Sized + ToOwned > const Deref for Cow < ' _ , B >
350
+ impl < B : ?Sized + ToOwned < COOP_PREFERRED > , const COOP_PREFERRED : bool > const Deref for Cow < ' _ , B , COOP_PREFERRED >
348
351
where
349
352
B :: Owned : ~const Borrow < B > ,
353
+ [ ( ) ; core:: alloc:: co_alloc_metadata_num_slots_with_preference :: < Global > ( COOP_PREFERRED ) ] : ,
350
354
{
351
355
type Target = B ;
352
356
@@ -359,12 +363,18 @@ where
359
363
}
360
364
361
365
#[ stable( feature = "rust1" , since = "1.0.0" ) ]
362
- impl < B : ?Sized > Eq for Cow < ' _ , B > where B : Eq + ToOwned { }
366
+ impl < B : ?Sized , const COOP_PREFERRED : bool > Eq for Cow < ' _ , B , COOP_PREFERRED >
367
+ where
368
+ B : Eq + ToOwned < COOP_PREFERRED > ,
369
+ [ ( ) ; core:: alloc:: co_alloc_metadata_num_slots_with_preference :: < Global > ( COOP_PREFERRED ) ] : ,
370
+
371
+ { }
363
372
364
373
#[ stable( feature = "rust1" , since = "1.0.0" ) ]
365
- impl < B : ?Sized > Ord for Cow < ' _ , B >
374
+ impl < B : ?Sized , const COOP_PREFERRED : bool > Ord for Cow < ' _ , B , COOP_PREFERRED >
366
375
where
367
- B : Ord + ToOwned ,
376
+ B : Ord + ToOwned < COOP_PREFERRED > ,
377
+ [ ( ) ; core:: alloc:: co_alloc_metadata_num_slots_with_preference :: < Global > ( COOP_PREFERRED ) ] : ,
368
378
{
369
379
#[ inline]
370
380
fn cmp ( & self , other : & Self ) -> Ordering {
@@ -373,24 +383,26 @@ where
373
383
}
374
384
375
385
#[ stable( feature = "rust1" , since = "1.0.0" ) ]
376
- impl < ' a , ' b , B : ?Sized , C : ?Sized > PartialEq < Cow < ' b , C > > for Cow < ' a , B >
386
+ impl < ' a , ' b , B : ?Sized , C : ?Sized , const COOP_PREFERRED : bool > PartialEq < Cow < ' b , C , COOP_PREFERRED > > for Cow < ' a , B , COOP_PREFERRED >
377
387
where
378
- B : PartialEq < C > + ToOwned ,
379
- C : ToOwned ,
388
+ B : PartialEq < C > + ToOwned < COOP_PREFERRED > ,
389
+ C : ToOwned < COOP_PREFERRED > ,
390
+ [ ( ) ; core:: alloc:: co_alloc_metadata_num_slots_with_preference :: < Global > ( COOP_PREFERRED ) ] : ,
380
391
{
381
392
#[ inline]
382
- fn eq ( & self , other : & Cow < ' b , C > ) -> bool {
393
+ fn eq ( & self , other : & Cow < ' b , C , COOP_PREFERRED > ) -> bool {
383
394
PartialEq :: eq ( & * * self , & * * other)
384
395
}
385
396
}
386
397
387
398
#[ stable( feature = "rust1" , since = "1.0.0" ) ]
388
- impl < ' a , B : ?Sized > PartialOrd for Cow < ' a , B >
399
+ impl < ' a , B : ?Sized , const COOP_PREFERRED : bool > PartialOrd for Cow < ' a , B , COOP_PREFERRED >
389
400
where
390
- B : PartialOrd + ToOwned ,
401
+ B : PartialOrd + ToOwned < COOP_PREFERRED > ,
402
+ [ ( ) ; core:: alloc:: co_alloc_metadata_num_slots_with_preference :: < Global > ( COOP_PREFERRED ) ] : ,
391
403
{
392
404
#[ inline]
393
- fn partial_cmp ( & self , other : & Cow < ' a , B > ) -> Option < Ordering > {
405
+ fn partial_cmp ( & self , other : & Cow < ' a , B , COOP_PREFERRED > ) -> Option < Ordering > {
394
406
PartialOrd :: partial_cmp ( & * * self , & * * other)
395
407
}
396
408
}
@@ -436,9 +448,10 @@ where
436
448
}
437
449
438
450
#[ stable( feature = "rust1" , since = "1.0.0" ) ]
439
- impl < B : ?Sized > Hash for Cow < ' _ , B >
451
+ impl < B : ?Sized , const COOP_PREFERRED : bool > Hash for Cow < ' _ , B , COOP_PREFERRED >
440
452
where
441
- B : Hash + ToOwned ,
453
+ B : Hash + ToOwned < COOP_PREFERRED > ,
454
+ [ ( ) ; core:: alloc:: co_alloc_metadata_num_slots_with_preference :: < Global > ( COOP_PREFERRED ) ] : ,
442
455
{
443
456
#[ inline]
444
457
fn hash < H : Hasher > ( & self , state : & mut H ) {
@@ -447,16 +460,20 @@ where
447
460
}
448
461
449
462
#[ stable( feature = "rust1" , since = "1.0.0" ) ]
450
- impl < T : ?Sized + ToOwned > AsRef < T > for Cow < ' _ , T > {
463
+ impl < T : ?Sized + ToOwned < COOP_PREFERRED > , const COOP_PREFERRED : bool > AsRef < T > for Cow < ' _ , T , COOP_PREFERRED >
464
+ where [ ( ) ; core:: alloc:: co_alloc_metadata_num_slots_with_preference :: < Global > ( COOP_PREFERRED ) ] : ,
465
+ {
451
466
fn as_ref ( & self ) -> & T {
452
467
self
453
468
}
454
469
}
455
470
456
471
#[ cfg( not( no_global_oom_handling) ) ]
457
472
#[ stable( feature = "cow_add" , since = "1.14.0" ) ]
458
- impl < ' a > Add < & ' a str > for Cow < ' a , str > {
459
- type Output = Cow < ' a , str > ;
473
+ impl < ' a , const COOP_PREFERRED : bool > Add < & ' a str > for Cow < ' a , str , COOP_PREFERRED >
474
+ where [ ( ) ; core:: alloc:: co_alloc_metadata_num_slots_with_preference :: < Global > ( COOP_PREFERRED ) ] : ,
475
+ {
476
+ type Output = Cow < ' a , str , COOP_PREFERRED > ;
460
477
461
478
#[ inline]
462
479
fn add ( mut self , rhs : & ' a str ) -> Self :: Output {
@@ -467,19 +484,23 @@ impl<'a> Add<&'a str> for Cow<'a, str> {
467
484
468
485
#[ cfg( not( no_global_oom_handling) ) ]
469
486
#[ stable( feature = "cow_add" , since = "1.14.0" ) ]
470
- impl < ' a > Add < Cow < ' a , str > > for Cow < ' a , str > {
471
- type Output = Cow < ' a , str > ;
487
+ impl < ' a , const COOP_PREFERRED : bool > Add < Cow < ' a , str , COOP_PREFERRED > > for Cow < ' a , str , COOP_PREFERRED >
488
+ where [ ( ) ; core:: alloc:: co_alloc_metadata_num_slots_with_preference :: < Global > ( COOP_PREFERRED ) ] : ,
489
+ {
490
+ type Output = Cow < ' a , str , COOP_PREFERRED > ;
472
491
473
492
#[ inline]
474
- fn add ( mut self , rhs : Cow < ' a , str > ) -> Self :: Output {
493
+ fn add ( mut self , rhs : Cow < ' a , str , COOP_PREFERRED > ) -> Self :: Output {
475
494
self += rhs;
476
495
self
477
496
}
478
497
}
479
498
480
499
#[ cfg( not( no_global_oom_handling) ) ]
481
500
#[ stable( feature = "cow_add" , since = "1.14.0" ) ]
482
- impl < ' a > AddAssign < & ' a str > for Cow < ' a , str > {
501
+ impl < ' a , const COOP_PREFERRED : bool > AddAssign < & ' a str > for Cow < ' a , str , COOP_PREFERRED >
502
+ where [ ( ) ; core:: alloc:: co_alloc_metadata_num_slots_with_preference :: < Global > ( COOP_PREFERRED ) ] : ,
503
+ {
483
504
fn add_assign ( & mut self , rhs : & ' a str ) {
484
505
if self . is_empty ( ) {
485
506
* self = Cow :: Borrowed ( rhs)
@@ -496,8 +517,10 @@ impl<'a> AddAssign<&'a str> for Cow<'a, str> {
496
517
497
518
#[ cfg( not( no_global_oom_handling) ) ]
498
519
#[ stable( feature = "cow_add" , since = "1.14.0" ) ]
499
- impl < ' a > AddAssign < Cow < ' a , str > > for Cow < ' a , str > {
500
- fn add_assign ( & mut self , rhs : Cow < ' a , str > ) {
520
+ impl < ' a , const COOP_PREFERRED : bool > AddAssign < Cow < ' a , str , COOP_PREFERRED > > for Cow < ' a , str , COOP_PREFERRED >
521
+ where [ ( ) ; core:: alloc:: co_alloc_metadata_num_slots_with_preference :: < Global > ( COOP_PREFERRED ) ] : ,
522
+ {
523
+ fn add_assign ( & mut self , rhs : Cow < ' a , str , COOP_PREFERRED > ) {
501
524
if self . is_empty ( ) {
502
525
* self = rhs
503
526
} else if !rhs. is_empty ( ) {
0 commit comments