@@ -18,9 +18,11 @@ use crate::string::String;
18
18
use Cow :: * ;
19
19
20
20
#[ 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 >
22
22
where
23
- B : ToOwned ,
23
+ B : ToOwned < COOP_PREFERRED > ,
24
+ [ ( ) ; core:: alloc:: co_alloc_metadata_num_slots_with_preference :: < Global > ( COOP_PREFERRED ) ] : ,
25
+
24
26
{
25
27
fn borrow ( & self ) -> & B {
26
28
& * * self
83
85
}
84
86
85
87
#[ 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
87
89
where
88
90
T : Clone ,
91
+ [ ( ) ; core:: alloc:: co_alloc_metadata_num_slots_with_preference :: < Global > ( COOP_PREFERRED ) ] : ,
89
92
{
90
93
type Owned = T ;
91
94
fn to_owned ( & self ) -> T {
@@ -180,21 +183,26 @@ where
180
183
/// ```
181
184
#[ stable( feature = "rust1" , since = "1.0.0" ) ]
182
185
#[ 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 ! ( ) } >
184
188
where
185
- B : ToOwned ,
189
+ B : ToOwned < COOP_PREFERRED > ,
190
+ [ ( ) ; core:: alloc:: co_alloc_metadata_num_slots_with_preference :: < Global > ( COOP_PREFERRED ) ] : ,
186
191
{
187
192
/// Borrowed data.
188
193
#[ stable( feature = "rust1" , since = "1.0.0" ) ]
189
194
Borrowed ( #[ stable( feature = "rust1" , since = "1.0.0" ) ] & ' a B ) ,
190
195
191
196
/// Owned data.
192
197
#[ 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 ) ,
194
199
}
195
200
196
201
#[ 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
+ {
198
206
fn clone ( & self ) -> Self {
199
207
match * self {
200
208
Borrowed ( b) => Borrowed ( b) ,
@@ -213,7 +221,10 @@ impl<B: ?Sized + ToOwned> Clone for Cow<'_, B> {
213
221
}
214
222
}
215
223
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
+ {
217
228
/// Returns true if the data is borrowed, i.e. if `to_mut` would require additional work.
218
229
///
219
230
/// # Examples
@@ -275,7 +286,7 @@ impl<B: ?Sized + ToOwned> Cow<'_, B> {
275
286
/// );
276
287
/// ```
277
288
#[ 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 {
279
290
match * self {
280
291
Borrowed ( borrowed) => {
281
292
* self = Owned ( borrowed. to_owned ( ) ) ;
@@ -323,7 +334,7 @@ impl<B: ?Sized + ToOwned> Cow<'_, B> {
323
334
/// );
324
335
/// ```
325
336
#[ 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 {
327
338
match self {
328
339
Borrowed ( borrowed) => borrowed. to_owned ( ) ,
329
340
Owned ( owned) => owned,
@@ -385,9 +396,10 @@ where
385
396
}
386
397
387
398
#[ 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 >
389
400
where
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 ) ] : ,
391
403
{
392
404
fn fmt ( & self , f : & mut fmt:: Formatter < ' _ > ) -> fmt:: Result {
393
405
match * self {
@@ -398,9 +410,10 @@ where
398
410
}
399
411
400
412
#[ 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 >
402
414
where
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 ) ] : ,
404
417
{
405
418
fn fmt ( & self , f : & mut fmt:: Formatter < ' _ > ) -> fmt:: Result {
406
419
match * self {
@@ -411,13 +424,14 @@ where
411
424
}
412
425
413
426
#[ 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 >
415
428
where
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 ) ] : ,
417
431
{
418
432
/// Creates an owned Cow<'a, B> with the default value for the contained owned value.
419
433
fn default ( ) -> Self {
420
- Owned ( <B as ToOwned >:: Owned :: default ( ) )
434
+ Owned ( <B as ToOwned < COOP_PREFERRED > >:: Owned :: default ( ) )
421
435
}
422
436
}
423
437
0 commit comments