14
14
// limitations under the License.
15
15
16
16
use crate :: displayer:: { DisplayProxy , DisplayerOf } ;
17
+ #[ cfg_attr( feature = "unstable_generic_const_own_type" , allow( deprecated) ) ]
17
18
use crate :: trait_flag:: { self , TraitFlags } ;
18
19
use core:: cmp:: Ordering ;
19
20
use core:: fmt;
@@ -180,12 +181,14 @@ use serde::{Deserialize, Deserializer, Serialize, Serializer};
180
181
/// let n_from_thread = std::thread::spawn(|| &N).join().unwrap();
181
182
/// assert_eq!(N, *n_from_thread);
182
183
/// ```
184
+ #[ cfg_attr( feature = "unstable_generic_const_own_type" , allow( deprecated) ) ]
183
185
#[ repr( transparent) ]
184
186
pub struct Amount < const TF : TraitFlags , Unit , Repr > (
185
187
Repr ,
186
188
PhantomData < core:: sync:: atomic:: AtomicPtr < Unit > > ,
187
189
) ;
188
190
191
+ #[ cfg_attr( feature = "unstable_generic_const_own_type" , allow( deprecated) ) ]
189
192
impl < const TF : TraitFlags , Unit , Repr : Copy > Amount < TF , Unit , Repr > {
190
193
// @TODO
191
194
/// Returns the wrapped value.
@@ -208,6 +211,7 @@ impl<const TF: TraitFlags, Unit, Repr: Copy> Amount<TF, Unit, Repr> {
208
211
}
209
212
}
210
213
214
+ #[ cfg_attr( feature = "unstable_generic_const_own_type" , allow( deprecated) ) ]
211
215
impl < const TF : TraitFlags , Unit , Repr > Amount < TF , Unit , Repr > {
212
216
/// `new` is a synonym for `from` that can be evaluated in
213
217
/// compile time. The main use-case of this functions is defining
@@ -217,6 +221,7 @@ impl<const TF: TraitFlags, Unit, Repr> Amount<TF, Unit, Repr> {
217
221
}
218
222
}
219
223
224
+ #[ cfg_attr( feature = "unstable_generic_const_own_type" , allow( deprecated) ) ]
220
225
impl < const TF : TraitFlags , Unit : Default , Repr > Amount < TF , Unit , Repr > {
221
226
// @TODO similar but without &self
222
227
//
@@ -242,6 +247,7 @@ impl<const TF: TraitFlags, Unit: Default, Repr> Amount<TF, Unit, Repr> {
242
247
}
243
248
}
244
249
250
+ #[ cfg_attr( feature = "unstable_generic_const_own_type" , allow( deprecated) ) ]
245
251
impl < const TF : TraitFlags , Unit , Repr > Amount < TF , Unit , Repr >
246
252
where
247
253
Unit : DisplayerOf < Self > , //@TODO cleanup: Amount<TF, Unit, Repr>>,
@@ -275,6 +281,7 @@ where
275
281
}
276
282
}
277
283
284
+ #[ cfg_attr( feature = "unstable_generic_const_own_type" , allow( deprecated) ) ]
278
285
impl < const TF : TraitFlags , Unit , Repr > From < Repr > for Amount < TF , Unit , Repr > {
279
286
fn from ( repr : Repr ) -> Self {
280
287
Self :: new ( repr)
@@ -287,6 +294,7 @@ impl<const TF: TraitFlags, Unit, Repr> From<Repr> for Amount<TF, Unit, Repr> {
287
294
// `PartialEq<Wrapper<T>>` require `T` to implement `PartialEq`, which
288
295
// is not what we want: `T` is phantom in our case.
289
296
297
+ #[ cfg_attr( feature = "unstable_generic_const_own_type" , allow( deprecated) ) ]
290
298
impl < const TF : TraitFlags , Unit , Repr : Clone > Clone for Amount < TF , Unit , Repr > {
291
299
fn clone ( & self ) -> Self {
292
300
Amount ( self . 0 . clone ( ) , PhantomData )
@@ -311,32 +319,38 @@ impl<Unit, Repr: Default> Default
311
319
}
312
320
}
313
321
322
+ #[ cfg_attr( feature = "unstable_generic_const_own_type" , allow( deprecated) ) ]
314
323
impl < const TF : TraitFlags , Unit , Repr : PartialEq > PartialEq for Amount < TF , Unit , Repr > {
315
324
fn eq ( & self , rhs : & Self ) -> bool {
316
325
self . 0 . eq ( & rhs. 0 )
317
326
}
318
327
}
319
328
329
+ #[ cfg_attr( feature = "unstable_generic_const_own_type" , allow( deprecated) ) ]
320
330
impl < const TF : TraitFlags , Unit , Repr : Eq > Eq for Amount < TF , Unit , Repr > { }
321
331
332
+ #[ cfg_attr( feature = "unstable_generic_const_own_type" , allow( deprecated) ) ]
322
333
impl < const TF : TraitFlags , Unit , Repr : PartialOrd > PartialOrd for Amount < TF , Unit , Repr > {
323
334
fn partial_cmp ( & self , rhs : & Self ) -> Option < Ordering > {
324
335
self . 0 . partial_cmp ( & rhs. 0 )
325
336
}
326
337
}
327
338
339
+ #[ cfg_attr( feature = "unstable_generic_const_own_type" , allow( deprecated) ) ]
328
340
impl < const TF : TraitFlags , Unit , Repr : Ord > Ord for Amount < TF , Unit , Repr > {
329
341
fn cmp ( & self , rhs : & Self ) -> Ordering {
330
342
self . 0 . cmp ( & rhs. 0 )
331
343
}
332
344
}
333
345
346
+ #[ cfg_attr( feature = "unstable_generic_const_own_type" , allow( deprecated) ) ]
334
347
impl < const TF : TraitFlags , Unit , Repr : Hash > Hash for Amount < TF , Unit , Repr > {
335
348
fn hash < H : Hasher > ( & self , state : & mut H ) {
336
349
self . 0 . hash ( state)
337
350
}
338
351
}
339
352
353
+ #[ cfg_attr( feature = "unstable_generic_const_own_type" , allow( deprecated) ) ]
340
354
impl < const TF : TraitFlags , Unit , Repr > Add for Amount < TF , Unit , Repr >
341
355
where
342
356
Repr : AddAssign + Copy ,
@@ -348,6 +362,7 @@ where
348
362
}
349
363
}
350
364
365
+ #[ cfg_attr( feature = "unstable_generic_const_own_type" , allow( deprecated) ) ]
351
366
impl < const TF : TraitFlags , Unit , Repr > AddAssign for Amount < TF , Unit , Repr >
352
367
where
353
368
Repr : AddAssign + Copy ,
@@ -357,6 +372,7 @@ where
357
372
}
358
373
}
359
374
375
+ #[ cfg_attr( feature = "unstable_generic_const_own_type" , allow( deprecated) ) ]
360
376
impl < const TF : TraitFlags , Unit , Repr > SubAssign for Amount < TF , Unit , Repr >
361
377
where
362
378
Repr : SubAssign + Copy ,
@@ -366,6 +382,7 @@ where
366
382
}
367
383
}
368
384
385
+ #[ cfg_attr( feature = "unstable_generic_const_own_type" , allow( deprecated) ) ]
369
386
impl < const TF : TraitFlags , Unit , Repr > Sub for Amount < TF , Unit , Repr >
370
387
where
371
388
Repr : SubAssign + Copy ,
@@ -378,6 +395,7 @@ where
378
395
}
379
396
}
380
397
398
+ #[ cfg_attr( feature = "unstable_generic_const_own_type" , allow( deprecated) ) ]
381
399
impl < const TF : TraitFlags , Unit , Repr > MulAssign < Repr > for Amount < TF , Unit , Repr >
382
400
where
383
401
Repr : MulAssign + Copy ,
@@ -387,6 +405,7 @@ where
387
405
}
388
406
}
389
407
408
+ #[ cfg_attr( feature = "unstable_generic_const_own_type" , allow( deprecated) ) ]
390
409
impl < const TF : TraitFlags , Unit , Repr > Mul < Repr > for Amount < TF , Unit , Repr >
391
410
where
392
411
Repr : MulAssign + Copy ,
@@ -399,6 +418,7 @@ where
399
418
}
400
419
}
401
420
421
+ #[ cfg_attr( feature = "unstable_generic_const_own_type" , allow( deprecated) ) ]
402
422
impl < const TF : TraitFlags , Unit , Repr > Div < Self > for Amount < TF , Unit , Repr >
403
423
where
404
424
Repr : Div < Repr > + Copy ,
@@ -410,6 +430,7 @@ where
410
430
}
411
431
}
412
432
433
+ #[ cfg_attr( feature = "unstable_generic_const_own_type" , allow( deprecated) ) ]
413
434
impl < const TF : TraitFlags , Unit , Repr > fmt:: Debug for Amount < TF , Unit , Repr >
414
435
where
415
436
Repr : fmt:: Debug ,
@@ -419,6 +440,7 @@ where
419
440
}
420
441
}
421
442
443
+ #[ cfg_attr( feature = "unstable_generic_const_own_type" , allow( deprecated) ) ]
422
444
impl < const TF : TraitFlags , Unit , Repr > fmt:: Display for Amount < TF , Unit , Repr >
423
445
where
424
446
Repr : fmt:: Display ,
@@ -435,13 +457,15 @@ where
435
457
// We want serialization format of `Repr` and the `Amount` to match
436
458
// exactly, that's why we have to provide custom instances.
437
459
#[ cfg( feature = "serde" ) ]
460
+ #[ cfg_attr( feature = "unstable_generic_const_own_type" , allow( deprecated) ) ]
438
461
impl < const TF : TraitFlags , Unit , Repr : Serialize > Serialize for Amount < TF , Unit , Repr > {
439
462
fn serialize < S : Serializer > ( & self , serializer : S ) -> Result < S :: Ok , S :: Error > {
440
463
self . 0 . serialize ( serializer)
441
464
}
442
465
}
443
466
444
467
#[ cfg( feature = "serde" ) ]
468
+ #[ cfg_attr( feature = "unstable_generic_const_own_type" , allow( deprecated) ) ]
445
469
impl < ' de , const TF : TraitFlags , Unit , Repr > Deserialize < ' de > for Amount < TF , Unit , Repr >
446
470
where
447
471
Repr : Deserialize < ' de > ,
0 commit comments