@@ -18,9 +18,11 @@ use crate::string::String;
1818use Cow :: * ;
1919
2020#[ stable( feature = "rust1" , since = "1.0.0" ) ]
21- impl < ' a , B : ?Sized > Borrow < B > for Cow < ' a , B >
21+ impl < ' a , B : ?Sized , const COOP_PREFERRED : bool > Borrow < B > for Cow < ' a , B , COOP_PREFERRED >
2222where
23- B : ToOwned ,
23+ B : ToOwned < COOP_PREFERRED > ,
24+ [ ( ) ; core:: alloc:: co_alloc_metadata_num_slots_with_preference :: < Global > ( COOP_PREFERRED ) ] : ,
25+
2426{
2527 fn borrow ( & self ) -> & B {
2628 & * * self
8385}
8486
8587#[ stable( feature = "rust1" , since = "1.0.0" ) ]
86- impl < T > ToOwned for T
88+ impl < T , const COOP_PREFERRED : bool > ToOwned < COOP_PREFERRED > for T
8789where
8890 T : Clone ,
91+ [ ( ) ; core:: alloc:: co_alloc_metadata_num_slots_with_preference :: < Global > ( COOP_PREFERRED ) ] : ,
8992{
9093 type Owned = T ;
9194 fn to_owned ( & self ) -> T {
@@ -180,21 +183,26 @@ where
180183/// ```
181184#[ stable( feature = "rust1" , since = "1.0.0" ) ]
182185#[ cfg_attr( not( test) , rustc_diagnostic_item = "Cow" ) ]
183- pub enum Cow < ' a , B : ?Sized + ' a >
186+ #[ allow( unused_braces) ]
187+ pub enum Cow < ' a , B : ?Sized + ' a , const COOP_PREFERRED : bool = { DEFAULT_COOP_PREFERRED ! ( ) } >
184188where
185- B : ToOwned ,
189+ B : ToOwned < COOP_PREFERRED > ,
190+ [ ( ) ; core:: alloc:: co_alloc_metadata_num_slots_with_preference :: < Global > ( COOP_PREFERRED ) ] : ,
186191{
187192 /// Borrowed data.
188193 #[ stable( feature = "rust1" , since = "1.0.0" ) ]
189194 Borrowed ( #[ stable( feature = "rust1" , since = "1.0.0" ) ] & ' a B ) ,
190195
191196 /// Owned data.
192197 #[ stable( feature = "rust1" , since = "1.0.0" ) ]
193- Owned ( #[ stable( feature = "rust1" , since = "1.0.0" ) ] <B as ToOwned >:: Owned ) ,
198+ Owned ( #[ stable( feature = "rust1" , since = "1.0.0" ) ] <B as ToOwned < COOP_PREFERRED > >:: Owned ) ,
194199}
195200
196201#[ stable( feature = "rust1" , since = "1.0.0" ) ]
197- impl < B : ?Sized + ToOwned > Clone for Cow < ' _ , B > {
202+ impl < B : ?Sized + ToOwned < COOP_PREFERRED > , const COOP_PREFERRED : bool > Clone for Cow < ' _ , B , COOP_PREFERRED >
203+ where
204+ [ ( ) ; core:: alloc:: co_alloc_metadata_num_slots_with_preference :: < Global > ( COOP_PREFERRED ) ] : ,
205+ {
198206 fn clone ( & self ) -> Self {
199207 match * self {
200208 Borrowed ( b) => Borrowed ( b) ,
@@ -213,7 +221,10 @@ impl<B: ?Sized + ToOwned> Clone for Cow<'_, B> {
213221 }
214222}
215223
216- impl < B : ?Sized + ToOwned > Cow < ' _ , B > {
224+ impl < B : ?Sized + ToOwned < COOP_PREFERRED > , const COOP_PREFERRED : bool > Cow < ' _ , B , COOP_PREFERRED >
225+ where
226+ [ ( ) ; core:: alloc:: co_alloc_metadata_num_slots_with_preference :: < Global > ( COOP_PREFERRED ) ] : ,
227+ {
217228 /// Returns true if the data is borrowed, i.e. if `to_mut` would require additional work.
218229 ///
219230 /// # Examples
@@ -275,7 +286,7 @@ impl<B: ?Sized + ToOwned> Cow<'_, B> {
275286 /// );
276287 /// ```
277288 #[ stable( feature = "rust1" , since = "1.0.0" ) ]
278- pub fn to_mut ( & mut self ) -> & mut <B as ToOwned >:: Owned {
289+ pub fn to_mut ( & mut self ) -> & mut <B as ToOwned < COOP_PREFERRED > >:: Owned {
279290 match * self {
280291 Borrowed ( borrowed) => {
281292 * self = Owned ( borrowed. to_owned ( ) ) ;
@@ -323,7 +334,7 @@ impl<B: ?Sized + ToOwned> Cow<'_, B> {
323334 /// );
324335 /// ```
325336 #[ stable( feature = "rust1" , since = "1.0.0" ) ]
326- pub fn into_owned ( self ) -> <B as ToOwned >:: Owned {
337+ pub fn into_owned ( self ) -> <B as ToOwned < COOP_PREFERRED > >:: Owned {
327338 match self {
328339 Borrowed ( borrowed) => borrowed. to_owned ( ) ,
329340 Owned ( owned) => owned,
@@ -385,9 +396,10 @@ where
385396}
386397
387398#[ stable( feature = "rust1" , since = "1.0.0" ) ]
388- impl < B : ?Sized > fmt:: Debug for Cow < ' _ , B >
399+ impl < B : ?Sized , const COOP_PREFERRED : bool > fmt:: Debug for Cow < ' _ , B , COOP_PREFERRED >
389400where
390- B : fmt:: Debug + ToOwned < Owned : fmt:: Debug > ,
401+ B : fmt:: Debug + ToOwned < COOP_PREFERRED , Owned : fmt:: Debug > ,
402+ [ ( ) ; core:: alloc:: co_alloc_metadata_num_slots_with_preference :: < Global > ( COOP_PREFERRED ) ] : ,
391403{
392404 fn fmt ( & self , f : & mut fmt:: Formatter < ' _ > ) -> fmt:: Result {
393405 match * self {
@@ -398,9 +410,10 @@ where
398410}
399411
400412#[ stable( feature = "rust1" , since = "1.0.0" ) ]
401- impl < B : ?Sized > fmt:: Display for Cow < ' _ , B >
413+ impl < B : ?Sized , const COOP_PREFERRED : bool > fmt:: Display for Cow < ' _ , B , COOP_PREFERRED >
402414where
403- B : fmt:: Display + ToOwned < Owned : fmt:: Display > ,
415+ B : fmt:: Display + ToOwned < COOP_PREFERRED , Owned : fmt:: Display > ,
416+ [ ( ) ; core:: alloc:: co_alloc_metadata_num_slots_with_preference :: < Global > ( COOP_PREFERRED ) ] : ,
404417{
405418 fn fmt ( & self , f : & mut fmt:: Formatter < ' _ > ) -> fmt:: Result {
406419 match * self {
@@ -411,13 +424,14 @@ where
411424}
412425
413426#[ stable( feature = "default" , since = "1.11.0" ) ]
414- impl < B : ?Sized > Default for Cow < ' _ , B >
427+ impl < B : ?Sized , const COOP_PREFERRED : bool > Default for Cow < ' _ , B , COOP_PREFERRED >
415428where
416- B : ToOwned < Owned : Default > ,
429+ B : ToOwned < COOP_PREFERRED , Owned : Default > ,
430+ [ ( ) ; core:: alloc:: co_alloc_metadata_num_slots_with_preference :: < Global > ( COOP_PREFERRED ) ] : ,
417431{
418432 /// Creates an owned Cow<'a, B> with the default value for the contained owned value.
419433 fn default ( ) -> Self {
420- Owned ( <B as ToOwned >:: Owned :: default ( ) )
434+ Owned ( <B as ToOwned < COOP_PREFERRED > >:: Owned :: default ( ) )
421435 }
422436}
423437
0 commit comments