@@ -17,6 +17,9 @@ use crate::string::String;
1717
1818use Cow :: * ;
1919
20+ // @FIXME check if used & needed
21+ pub ( crate ) const BORROW_COOP_PREFERRED : bool = DEFAULT_COOP_PREFERRED ! ( ) ;
22+
2023#[ stable( feature = "rust1" , since = "1.0.0" ) ]
2124impl < ' a , B : ?Sized , const COOP_PREFERRED : bool > Borrow < B > for Cow < ' a , B , COOP_PREFERRED >
2225where
@@ -344,9 +347,10 @@ where
344347
345348#[ stable( feature = "rust1" , since = "1.0.0" ) ]
346349#[ 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 >
348351where
349352 B :: Owned : ~const Borrow < B > ,
353+ [ ( ) ; core:: alloc:: co_alloc_metadata_num_slots_with_preference :: < Global > ( COOP_PREFERRED ) ] : ,
350354{
351355 type Target = B ;
352356
@@ -359,12 +363,18 @@ where
359363}
360364
361365#[ 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+ { }
363372
364373#[ 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 >
366375where
367- B : Ord + ToOwned ,
376+ B : Ord + ToOwned < COOP_PREFERRED > ,
377+ [ ( ) ; core:: alloc:: co_alloc_metadata_num_slots_with_preference :: < Global > ( COOP_PREFERRED ) ] : ,
368378{
369379 #[ inline]
370380 fn cmp ( & self , other : & Self ) -> Ordering {
@@ -373,24 +383,26 @@ where
373383}
374384
375385#[ 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 >
377387where
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 ) ] : ,
380391{
381392 #[ inline]
382- fn eq ( & self , other : & Cow < ' b , C > ) -> bool {
393+ fn eq ( & self , other : & Cow < ' b , C , COOP_PREFERRED > ) -> bool {
383394 PartialEq :: eq ( & * * self , & * * other)
384395 }
385396}
386397
387398#[ 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 >
389400where
390- B : PartialOrd + ToOwned ,
401+ B : PartialOrd + ToOwned < COOP_PREFERRED > ,
402+ [ ( ) ; core:: alloc:: co_alloc_metadata_num_slots_with_preference :: < Global > ( COOP_PREFERRED ) ] : ,
391403{
392404 #[ 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 > {
394406 PartialOrd :: partial_cmp ( & * * self , & * * other)
395407 }
396408}
@@ -436,9 +448,10 @@ where
436448}
437449
438450#[ 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 >
440452where
441- B : Hash + ToOwned ,
453+ B : Hash + ToOwned < COOP_PREFERRED > ,
454+ [ ( ) ; core:: alloc:: co_alloc_metadata_num_slots_with_preference :: < Global > ( COOP_PREFERRED ) ] : ,
442455{
443456 #[ inline]
444457 fn hash < H : Hasher > ( & self , state : & mut H ) {
@@ -447,16 +460,20 @@ where
447460}
448461
449462#[ 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+ {
451466 fn as_ref ( & self ) -> & T {
452467 self
453468 }
454469}
455470
456471#[ cfg( not( no_global_oom_handling) ) ]
457472#[ 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 > ;
460477
461478 #[ inline]
462479 fn add ( mut self , rhs : & ' a str ) -> Self :: Output {
@@ -467,19 +484,23 @@ impl<'a> Add<&'a str> for Cow<'a, str> {
467484
468485#[ cfg( not( no_global_oom_handling) ) ]
469486#[ 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 > ;
472491
473492 #[ 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 {
475494 self += rhs;
476495 self
477496 }
478497}
479498
480499#[ cfg( not( no_global_oom_handling) ) ]
481500#[ 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+ {
483504 fn add_assign ( & mut self , rhs : & ' a str ) {
484505 if self . is_empty ( ) {
485506 * self = Cow :: Borrowed ( rhs)
@@ -496,8 +517,10 @@ impl<'a> AddAssign<&'a str> for Cow<'a, str> {
496517
497518#[ cfg( not( no_global_oom_handling) ) ]
498519#[ 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 > ) {
501524 if self . is_empty ( ) {
502525 * self = rhs
503526 } else if !rhs. is_empty ( ) {
0 commit comments